-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [BUG] fixes an incorrect reference to the old create contract class for v2 (#1661) * fixes an incorrect reference to the old create contract class for v2 * adds test for create contract v1 in sub invoke * account for invocations that follow the deployer pattern in create contract types, add branch for craete contract v2 in invocation crawler for sac cases * updates tests for sac create constructor args and adds optional component to render them * removes comment in tests * adds unit test and jest view tests for creater contract deployer pattern (#1668)
- Loading branch information
1 parent
1a85fb3
commit 64d0057
Showing
4 changed files
with
186 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
Address, | ||
Keypair, | ||
Operation, | ||
scValToNative, | ||
TransactionBuilder, | ||
xdr, | ||
} from "stellar-sdk"; | ||
|
||
import { getInvocationArgs, buildInvocationTree } from "../soroban"; | ||
import { TEST_PUBLIC_KEY } from "popup/__testHelpers__"; | ||
import { TESTNET_NETWORK_DETAILS } from "@shared/constants/stellar"; | ||
|
||
describe("getInvocationArgs", () => { | ||
it("can parse a create contract v1 xdr class", () => { | ||
const assetCode = "KHL"; | ||
const assetType = new xdr.AlphaNum4({ | ||
assetCode: Buffer.from(assetCode), | ||
issuer: Keypair.fromPublicKey(TEST_PUBLIC_KEY).xdrAccountId(), | ||
}); | ||
const args = new xdr.CreateContractArgs({ | ||
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAsset( | ||
xdr.Asset.assetTypeCreditAlphanum4(assetType), | ||
), | ||
executable: xdr.ContractExecutable.contractExecutableStellarAsset(), | ||
}); | ||
const authorizedFn = | ||
xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeCreateContractHostFn( | ||
args, | ||
); | ||
const authorizedInvocation = new xdr.SorobanAuthorizedInvocation({ | ||
function: authorizedFn, | ||
subInvocations: [], | ||
}); | ||
const invocationArgs = getInvocationArgs(authorizedInvocation); | ||
expect(invocationArgs).toEqual({ | ||
type: "sac", | ||
asset: `${assetCode}:${TEST_PUBLIC_KEY}`, | ||
}); | ||
}); | ||
it("can parse a create contract v2 xdr class", () => { | ||
const assetCode = "KHL"; | ||
const assetType = new xdr.AlphaNum4({ | ||
assetCode: Buffer.from(assetCode), | ||
issuer: Keypair.fromPublicKey(TEST_PUBLIC_KEY).xdrAccountId(), | ||
}); | ||
const args = new xdr.CreateContractArgsV2({ | ||
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAsset( | ||
xdr.Asset.assetTypeCreditAlphanum4(assetType), | ||
), | ||
executable: xdr.ContractExecutable.contractExecutableStellarAsset(), | ||
constructorArgs: [new Address(TEST_PUBLIC_KEY).toScVal()], | ||
}); | ||
const authorizedFn = | ||
xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeCreateContractV2HostFn( | ||
args, | ||
); | ||
const authorizedInvocation = new xdr.SorobanAuthorizedInvocation({ | ||
function: authorizedFn, | ||
subInvocations: [], | ||
}); | ||
const invocationArgs = getInvocationArgs(authorizedInvocation); | ||
expect(invocationArgs).toEqual({ | ||
type: "sac", | ||
asset: `${assetCode}:${TEST_PUBLIC_KEY}`, | ||
args: args.constructorArgs(), | ||
}); | ||
}); | ||
it("can parse a create contract v2 xdr for the deployer pattern", () => { | ||
const xdr = | ||
"AAAAAgAAAABngBTmbmUycqG2cAMHcomSR80dRzGtKzxM6gb3yySD5AHs+0gAAAGnAAAALwAAAAEAAAAAAAAAAAAAAABnNhxOAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAAB7NAU3oaYgmlpUsvzZfe9VHPtVP2GAv4RaBFqcvtQCMUAAAAGZGVwbG95AAAAAAAIAAAAEgAAAAAAAAAAZ4AU5m5lMnKhtnADB3KJkkfNHUcxrSs8TOoG98skg+QAAAANAAAAIBGajC6rX3MsGNdSFCbhA4FR+oN1BsY93KF8aFHi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NQcdhbR8THxWF04TpyJFUAAAAFAAAAAEAbsVOAAC4OAAABigAAAAAAez65AAAAAA="; | ||
const tx = TransactionBuilder.fromXDR( | ||
xdr, | ||
TESTNET_NETWORK_DETAILS.networkPassphrase, | ||
); | ||
const op = tx.operations[0]; | ||
for (const authEntry of op.auth || []) { | ||
const rootInvocation = authEntry.rootInvocation(); | ||
const tree = buildInvocationTree(rootInvocation); | ||
expect(tree.type).toEqual("execute"); | ||
expect(tree.args.source).toEqual( | ||
"CDWNAFG6Q2MIE2LJKLF7GZPXXVKHH3KU7WDAF7QRNAIWU4X3KAEMLZTN", | ||
); | ||
expect(tree.args.function).toEqual("deploy"); | ||
for (const subInvocation of tree.invocations) { | ||
if (subInvocation.type === "create") { | ||
expect(subInvocation.args.constructorArgs).toStrictEqual([]); | ||
} | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters