-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: various bugs with constants and BaseTrait inheritance in traits (#…
…1591) * fix: support overriding constant and methods of BaseTrait * fix: forbid traits inherit implicitly from BaseTrait * fix: check that the overridden constant has a super constant
- Loading branch information
Showing
33 changed files
with
8,339 additions
and
4,377 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
36 changes: 36 additions & 0 deletions
36
src/test/e2e-emulated/base-trait-constant-override-1.spec.ts
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,36 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { TraitsConstantContract } from "./contracts/output/base-trait-constant-override-1_TraitsConstantContract"; | ||
import "@ton/test-utils"; | ||
|
||
describe("base-trait-constant-override-1", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<TraitsConstantContract>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
treasure = await blockchain.treasury("treasure"); | ||
|
||
contract = blockchain.openContract( | ||
await TraitsConstantContract.fromInit(), | ||
); | ||
|
||
const deployResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("0.5") }, | ||
null, | ||
); | ||
|
||
expect(deployResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
deploy: true, | ||
}); | ||
}); | ||
|
||
it("should override constant correctly", async () => { | ||
expect(await contract.getConstant()).toEqual(100n); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
src/test/e2e-emulated/base-trait-constant-override-2.spec.ts
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,36 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { TraitsConstantContract } from "./contracts/output/base-trait-constant-override-2_TraitsConstantContract"; | ||
import "@ton/test-utils"; | ||
|
||
describe("base-trait-constant-override-2", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<TraitsConstantContract>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
treasure = await blockchain.treasury("treasure"); | ||
|
||
contract = blockchain.openContract( | ||
await TraitsConstantContract.fromInit(), | ||
); | ||
|
||
const deployResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("0.5") }, | ||
null, | ||
); | ||
|
||
expect(deployResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
deploy: true, | ||
}); | ||
}); | ||
|
||
it("should override constant correctly", async () => { | ||
expect(await contract.getConstant()).toEqual(10000n); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
src/test/e2e-emulated/base-trait-function-override.spec.ts
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,36 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { BaseTraitsFunctionContract } from "./contracts/output/base-trait-function-override_BaseTraitsFunctionContract"; | ||
import "@ton/test-utils"; | ||
|
||
describe("base-trait-function-override", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<BaseTraitsFunctionContract>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
treasure = await blockchain.treasury("treasure"); | ||
|
||
contract = blockchain.openContract( | ||
await BaseTraitsFunctionContract.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 override function correctly", async () => { | ||
expect(await contract.getValue()).toEqual(1000n); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/test/e2e-emulated/contracts/base-trait-constant-override-1.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,13 @@ | ||
trait OverrideBaseTraitConstant with BaseTrait { | ||
override const storageReserve: Int = 100; | ||
} | ||
|
||
contract TraitsConstantContract with OverrideBaseTraitConstant { | ||
receive() { | ||
// deploy | ||
} | ||
|
||
get fun constant(): Int { | ||
return self.storageReserve; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/e2e-emulated/contracts/base-trait-constant-override-2.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,17 @@ | ||
trait OverrideBaseTraitConstantWithVirtual with BaseTrait { | ||
override virtual const storageReserve: Int = 100; | ||
} | ||
|
||
trait OverrideOverridden with OverrideBaseTraitConstantWithVirtual { | ||
override const storageReserve: Int = 10000; | ||
} | ||
|
||
contract TraitsConstantContract with OverrideOverridden { | ||
receive() { | ||
// deploy | ||
} | ||
|
||
get fun constant(): Int { | ||
return self.storageReserve; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/e2e-emulated/contracts/base-trait-function-override.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,20 @@ | ||
trait OverrideBaseTraitFunction with BaseTrait { | ||
value: Int; | ||
|
||
override fun notify(body: Cell?) { | ||
self.value = 1000; | ||
} | ||
} | ||
|
||
contract BaseTraitsFunctionContract with OverrideBaseTraitFunction { | ||
value: Int = 0; | ||
|
||
receive() { | ||
// deploy | ||
} | ||
|
||
get fun value(): Int { | ||
self.notify(null); | ||
return self.value; | ||
} | ||
} |
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
Oops, something went wrong.