-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(asm): use multi-line strings in FunC and add some e2e tests (#825)
- Loading branch information
Showing
8 changed files
with
135 additions
and
3 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { AsmFunctionsTester as TestContract } from "./contracts/output/asm-functions_AsmFunctionsTester"; | ||
import "@ton/test-utils"; | ||
|
||
describe("asm functions", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<TestContract>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
blockchain.verbosity.print = false; | ||
treasure = await blockchain.treasury("treasure"); | ||
|
||
contract = blockchain.openContract(await TestContract.fromInit()); | ||
|
||
const deployResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
null, | ||
); | ||
|
||
expect(deployResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
deploy: true, | ||
}); | ||
}); | ||
|
||
it("should implement asm functions correctly", async () => { | ||
expect(await contract.getTestAsmStoreDict()).toEqual(true); | ||
expect(await contract.getTestAsmLoadCoins()).toEqual(true); | ||
expect(await contract.getTestAsmLoadInt()).toEqual(true); | ||
expect(await contract.getTestAsmDebugStr()).toEqual(true); | ||
}); | ||
}); |
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,59 @@ | ||
contract AsmFunctionsTester { | ||
/// To handle deployment | ||
receive() {} | ||
|
||
get fun testAsmStoreDict(): Bool { | ||
let m: map<Int, Int> = emptyMap(); | ||
m.set(35, 34); | ||
m.set(42, 27); | ||
|
||
let s = beginCell().asmStoreDict(m.asCell()).asSlice(); | ||
let m2: map<Int, Int> = s.asmLoadMapIntInt().val; | ||
|
||
return m2 == m; | ||
} | ||
|
||
get fun testAsmLoadCoins(): Bool { | ||
let s = beginCell().storeCoins(42).asSlice(); | ||
return s.asmLoadCoins().val == 42; | ||
} | ||
|
||
get fun testAsmLoadInt(): Bool { | ||
let s = beginCell().storeInt(42, 7).asSlice(); | ||
return s.asmLoadInt(7).val == 42; | ||
} | ||
|
||
get fun testAsmDebugStr(): Bool { | ||
debugStr(); | ||
return true; | ||
} | ||
} | ||
|
||
// Functions to test | ||
|
||
asm(c self) extends fun asmStoreDict(self: Builder, c: Cell?): Builder { STDICT } | ||
|
||
asm extends fun asmLoadMapIntInt(self: Slice): MapIntIntSlice { LDDICT } | ||
|
||
asm extends fun asmLoadCoins(self: Slice): IntSlice { LDVARUINT16 } | ||
|
||
asm(self len -> 1 0) extends fun asmLoadInt(self: Slice, len: Int): SliceInt { LDIX } | ||
|
||
asm fun debugStr() { "Works!" DEBUGSTR } | ||
|
||
// Helper Structs | ||
|
||
struct MapIntIntSlice { | ||
val: map<Int, Int>; | ||
rem: Slice; | ||
} | ||
|
||
struct IntSlice { | ||
val: Int; | ||
rem: Slice; | ||
} | ||
|
||
struct SliceInt { | ||
rem: Slice; | ||
val: Int; | ||
} |
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