-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add traversing of
init
AST when filling dependsOn
- Loading branch information
Showing
7 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`initof should implement initof correctly - 2 1`] = ` | ||
[ | ||
{ | ||
"$seq": 0, | ||
"events": [ | ||
{ | ||
"$type": "deploy", | ||
}, | ||
{ | ||
"$type": "received", | ||
"message": { | ||
"body": { | ||
"text": "aa", | ||
"type": "text", | ||
}, | ||
"bounce": true, | ||
"from": "@treasure(treasure)", | ||
"to": "kQBMKzwvmyn0kLoIPFPZ3N1raKFO3S-_K7-i-wqoJff5C3FN", | ||
"type": "internal", | ||
"value": "10", | ||
}, | ||
}, | ||
{ | ||
"$type": "processed", | ||
"gasUsed": 10085n, | ||
}, | ||
], | ||
}, | ||
] | ||
`; |
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,19 @@ | ||
contract B { | ||
owner: Address; | ||
init(addr: Address){ | ||
self.owner = addr; | ||
} | ||
} | ||
|
||
fun get_init(addr: Address): StateInit { | ||
return initOf B(addr); | ||
} | ||
|
||
contract A { | ||
receive("aa") { | ||
let c1: StateInit = get_init(myAddress()); | ||
dump(c1.data); | ||
let c2: StateInit = initOf B(myAddress()); | ||
dump(c2.data); | ||
} | ||
} |
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,30 @@ | ||
import "@stdlib/deploy"; | ||
|
||
message(42) Foo { } | ||
|
||
contract TestNested with Deployable { | ||
init() { dump("Nested----init@SUCCESS") } | ||
} | ||
|
||
contract TestInit with Deployable { | ||
init() { | ||
try { | ||
let init: StateInit = initOf TestNested(); | ||
dump("init@TestInit-1"); | ||
send(SendParameters { | ||
to: contractAddress(init), | ||
value: 0, | ||
mode: SendIgnoreErrors | SendRemainingValue, | ||
code: init.code, | ||
data: init.data, | ||
body: Deploy { queryId: 0 }.toCell(), | ||
}); | ||
dump("init@TestInit-SUCCESS"); | ||
} catch (e) { | ||
dump("ERROR@TestInit"); | ||
dump(e); | ||
} | ||
} | ||
|
||
receive(_: Foo) {} | ||
} |
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,43 @@ | ||
import { toNano } from "@ton/core"; | ||
import { ContractSystem } from "@tact-lang/emulator"; | ||
import { __DANGER_resetNodeId } from "../../grammar/ast"; | ||
import { TestInit } from "./contracts/output/initof_TestInit"; | ||
import { A } from "./contracts/output/initof-2_A"; | ||
|
||
describe("initof", () => { | ||
beforeEach(() => { | ||
__DANGER_resetNodeId(); | ||
}); | ||
it("should implement initof correctly - 1", async () => { | ||
// Init | ||
const system = await ContractSystem.create(); | ||
const treasure = system.treasure("treasure"); | ||
const contract = system.open(await TestInit.fromInit()); | ||
const logger = system.log(contract.address); | ||
await contract.send( | ||
treasure, | ||
{ value: toNano("10") }, | ||
{ | ||
$$type: "Deploy", | ||
queryId: 0n, | ||
}, | ||
); | ||
await system.run(); | ||
|
||
const res = logger.collect(); | ||
|
||
expect(res.includes("init@TestInit-SUCCESS")).toBe(true); | ||
expect(res.includes("ERROR@TestInit")).toBe(false); | ||
}); | ||
it("should implement initof correctly - 2", async () => { | ||
// Init | ||
const system = await ContractSystem.create(); | ||
const treasure = system.treasure("treasure"); | ||
const contract = system.open(await A.fromInit()); | ||
const tracker = system.track(contract.address); | ||
await contract.send(treasure, { value: toNano("10") }, "aa"); | ||
await system.run(); | ||
|
||
expect(tracker.collect()).toMatchSnapshot(); | ||
}); | ||
}); |
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