Skip to content

Commit

Permalink
Test script vm with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
polarker committed Aug 15, 2024
1 parent 0dd11e2 commit 0f9a68a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .project.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@
},
"MultiDeposit": {
"sourceFile": "test/transact.ral",
"sourceCodeHash": "92acc48b107b7c552d1f94ae9a07b41215c0359bb10a3aae7d1a10662f654117",
"sourceCodeHash": "04184bcb0fbfe358d2175574d6479ec9882445ef09a1bc521f3e742847afceb6",
"bytecodeDebugPatch": "",
"codeHashDebug": ""
},
"MultiWithdraw": {
"sourceFile": "test/transact.ral",
"sourceCodeHash": "92acc48b107b7c552d1f94ae9a07b41215c0359bb10a3aae7d1a10662f654117",
"sourceCodeHash": "04184bcb0fbfe358d2175574d6479ec9882445ef09a1bc521f3e742847afceb6",
"bytecodeDebugPatch": "",
"codeHashDebug": ""
},
Expand Down Expand Up @@ -300,7 +300,7 @@
},
"Transact": {
"sourceFile": "test/transact.ral",
"sourceCodeHash": "92acc48b107b7c552d1f94ae9a07b41215c0359bb10a3aae7d1a10662f654117",
"sourceCodeHash": "04184bcb0fbfe358d2175574d6479ec9882445ef09a1bc521f3e742847afceb6",
"bytecodeDebugPatch": "",
"codeHashDebug": "85e3e9a803741af8e92bd43b1b07cde53f39b86cab0ef1a85bab12b10d691b55"
},
Expand Down
9 changes: 3 additions & 6 deletions artifacts/test/MultiDeposit.ral.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"version": "v3.5.2",
"name": "MultiDeposit",
"bytecodeTemplate": "0101030000004020b413c40de0b6b3a7640000a20c0c{0}0100b413c40de0b6b3a7640000a20c0c{1}0100b4{2}13c40de0b6b3a7640000a313c40de0b6b3a76400000d0c{0}0102b4{2}13c40de0b6b3a7640000a313c40de0b6b3a76400000d0c{1}0102",
"bytecodeTemplate": "0101030002004024{0}{1}17011700b413c40de0b6b3a7640000a20c0c16000100b413c40de0b6b3a7640000a20c0c16010100b4{2}13c40de0b6b3a7640000a313c40de0b6b3a76400000d0c16000102b4{2}13c40de0b6b3a7640000a313c40de0b6b3a76400000d0c16010102",
"fieldsSig": {
"names": [
"c0",
"c1",
"c",
"tokenId"
],
"types": [
"Transact",
"Transact",
"[Transact;2]",
"ByteVec"
],
"isMutable": [
false,
false,
false
]
Expand Down
9 changes: 3 additions & 6 deletions artifacts/test/MultiWithdraw.ral.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{
"version": "v3.5.2",
"name": "MultiWithdraw",
"bytecodeTemplate": "010103000000120c0c{0}01010c0c{1}010113c40de0b6b3a76400000d0c{0}010313c40de0b6b3a76400000d0c{1}0103",
"bytecodeTemplate": "01010300020016{0}{1}170117000c0c160001010c0c1601010113c40de0b6b3a76400000d0c1600010313c40de0b6b3a76400000d0c16010103",
"fieldsSig": {
"names": [
"c0",
"c1"
"c"
],
"types": [
"Transact",
"Transact"
"[Transact;2]"
],
"isMutable": [
false,
false
]
},
Expand Down
6 changes: 2 additions & 4 deletions artifacts/ts/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,15 @@ export const MintNFTTest = new ExecutableScript<{
);

export const MultiDeposit = new ExecutableScript<{
c0: HexString;
c1: HexString;
c: [HexString, HexString];
tokenId: HexString;
}>(
Script.fromJson(MultiDepositScriptJson, "", AllStructs),
getContractByCodeHash
);

export const MultiWithdraw = new ExecutableScript<{
c0: HexString;
c1: HexString;
c: [HexString, HexString];
}>(
Script.fromJson(MultiWithdrawScriptJson, "", AllStructs),
getContractByCodeHash
Expand Down
20 changes: 10 additions & 10 deletions contracts/test/transact.ral
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ Contract Transact(
}
}

TxScript MultiDeposit(c0: Transact, c1: Transact, tokenId: ByteVec) {
c0.deposit{callerAddress!() -> ALPH: 1 alph}()
c1.deposit{callerAddress!() -> ALPH: 1 alph}()
c0.depositToken{callerAddress!() -> tokenId: 1e18}(1e18)
c1.depositToken{callerAddress!() -> tokenId: 1e18}(1e18)
TxScript MultiDeposit(c: [Transact; 2], tokenId: ByteVec) {
c[0].deposit{callerAddress!() -> ALPH: 1 alph}()
c[1].deposit{callerAddress!() -> ALPH: 1 alph}()
c[0].depositToken{callerAddress!() -> tokenId: 1e18}(1e18)
c[1].depositToken{callerAddress!() -> tokenId: 1e18}(1e18)
}

TxScript MultiWithdraw(c0: Transact, c1: Transact) {
c0.withdraw()
c1.withdraw()
c0.withdrawToken(1e18)
c1.withdrawToken(1e18)
TxScript MultiWithdraw(c: [Transact; 2]) {
c[0].withdraw()
c[1].withdraw()
c[0].withdrawToken(1e18)
c[1].withdrawToken(1e18)
}
4 changes: 2 additions & 2 deletions test/transact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('transact', function () {
const deposits = await MultiDeposit.execute(signer, {
attoAlphAmount: ONE_ALPH * 2n,
tokens: [{ id: tokenId, amount: 10n ** 18n * 2n }],
initialFields: { c0: instance0.address, c1: instance1.address, tokenId }
initialFields: { c: [instance0.address, instance1.address], tokenId }
})
const depositsCalls = ScriptSimulator.extractContractCallsWithErrors(deposits.unsignedTx)
expect(depositsCalls.length).toBe(4)
Expand All @@ -237,7 +237,7 @@ describe('transact', function () {

const withdraws = await MultiWithdraw.execute(signer, {
attoAlphAmount: DUST_AMOUNT * 2n,
initialFields: { c0: instance0.address, c1: instance1.address }
initialFields: { c: [instance0.address, instance1.address] }
})
const withdrawsCalls = ScriptSimulator.extractContractCallsWithErrors(withdraws.unsignedTx)
expect(withdrawsCalls.length).toBe(4)
Expand Down

0 comments on commit 0f9a68a

Please sign in to comment.