-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow constant/trait constants depend on each other (#1622)
- Loading branch information
Showing
15 changed files
with
222 additions
and
9 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
9 changes: 9 additions & 0 deletions
9
src/test/compilation-failed/contracts/const-eval-self-constant-assign-field.tact
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,9 @@ | ||
contract Test { | ||
const A: Int = self.value; | ||
|
||
value: Int = 10; | ||
|
||
get fun getConstant(): Int { | ||
return self.A; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...lation-failed/contracts/const-eval-self-constant-circular-dependency-self-assignment.tact
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,7 @@ | ||
contract Test { | ||
const A: Int = self.A; | ||
|
||
get fun getConstant(): Int { | ||
return A; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/compilation-failed/contracts/const-eval-self-constant-circular-dependency.tact
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,8 @@ | ||
contract Test { | ||
const A: Int = self.C; | ||
const C: Int = self.A; | ||
|
||
get fun getConstant(): Int { | ||
return self.C; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/compilation-failed/contracts/const-eval-self-constant-deep-circular-dependency.tact
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,11 @@ | ||
contract Test { | ||
const A: Int = self.E; | ||
const B: Int = self.A; | ||
const C: Int = self.B; | ||
const D: Int = self.C; | ||
const E: Int = self.D; | ||
|
||
get fun getConstant(): Int { | ||
return self.E; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...test/compilation-failed/contracts/const-eval-self-constant-with-method-call-in-value.tact
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,10 @@ | ||
contract Test { | ||
a: Int = 1; | ||
|
||
const B: Int = 10; | ||
const A: Int = self.B + self.test(); | ||
|
||
fun test(): Int { | ||
return self.a; | ||
} | ||
} |
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,41 @@ | ||
trait WithConstant { | ||
const TraitA: Int = 41; | ||
const TraitB: Int = self.TraitA + 1; | ||
|
||
const TraitA2: Int = 41; | ||
const TraitC2: Int = self.TraitA2 + 1 + self.TraitB2; | ||
const TraitB2: Int = 9; | ||
} | ||
|
||
contract ConstantTester with WithConstant { | ||
const A: Int = 41; | ||
const B: Int = self.A + 1; | ||
|
||
const A2: Int = 41; | ||
const C2: Int = self.A2 + 1 + self.B2; | ||
const B2: Int = 9; | ||
|
||
value: Int = self.B2 + self.C2 + self.TraitB2; | ||
|
||
receive() {} | ||
|
||
get fun b(): Int { | ||
return self.B; | ||
} | ||
|
||
get fun c2(): Int { | ||
return self.C2; | ||
} | ||
|
||
get fun value(): Int { | ||
return self.value; | ||
} | ||
|
||
get fun traitB(): Int { | ||
return self.TraitB; | ||
} | ||
|
||
get fun traitC2(): Int { | ||
return self.TraitC2; | ||
} | ||
} |
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 { ConstantTester } from "./contracts/output/self-constants_ConstantTester"; | ||
import "@ton/test-utils"; | ||
|
||
describe("self-constants", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<ConstantTester>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
blockchain.verbosity.print = false; | ||
treasure = await blockchain.treasury("treasure"); | ||
|
||
contract = blockchain.openContract(await ConstantTester.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 self constants correctly", async () => { | ||
expect(await contract.getB()).toEqual(42n); | ||
expect(await contract.getC2()).toEqual(51n); | ||
expect(await contract.getValue()).toEqual(69n); | ||
expect(await contract.getTraitB()).toEqual(42n); | ||
expect(await contract.getTraitC2()).toEqual(51n); | ||
}); | ||
}); |
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,8 @@ | ||
primitive Int; | ||
|
||
trait BaseTrait { } | ||
|
||
trait TestTrait { | ||
const A: Int = 100; | ||
const B: Int = A; | ||
} |