-
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.
test: Tact-reserved and general compute phase exit codes
With the correction of error list generated for the `.md` compilation report
- Loading branch information
Showing
10 changed files
with
717 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { ComputePhaseErrorsTester as TestContract } from "./contracts/output/compute-phase-errors_ComputePhaseErrorsTester"; | ||
import "@ton/test-utils"; | ||
|
||
describe("compute phase errors", () => { | ||
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", { | ||
resetBalanceIfZero: true, | ||
}); | ||
|
||
contract = blockchain.openContract(await TestContract.fromInit()); | ||
|
||
const deployResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("100000") }, | ||
null, | ||
); | ||
|
||
expect(deployResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
deploy: true, | ||
}); | ||
}); | ||
|
||
// 0: success | ||
it("should test exit code 0", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"0", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
exitCode: 0, | ||
}); | ||
}); | ||
|
||
// 1: alt. success code | ||
it("should test exit code 1", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"1", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
exitCode: 1, | ||
}); | ||
}); | ||
|
||
// 2: stack underflow | ||
it("should test exit code 2", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"2", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 2, | ||
}); | ||
}); | ||
|
||
// 3: Stack overflow | ||
it("should test exit code 3", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"3", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 3, | ||
}); | ||
}); | ||
|
||
// 4: Integer overflow | ||
it("should test exit code 4", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"4", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 4, | ||
}); | ||
}); | ||
|
||
// 5: Integer out of range | ||
it("should test exit code 5", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"5", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 5, | ||
}); | ||
}); | ||
|
||
// 6: Invalid opcode | ||
it("should test exit code 6", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"6", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 6, | ||
}); | ||
}); | ||
|
||
// 7: Type check error | ||
it("should test exit code 7", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"7", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 7, | ||
}); | ||
}); | ||
|
||
// 8: Cell overflow | ||
it("should test exit code 8", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"8", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 8, | ||
}); | ||
}); | ||
|
||
// 9: Cell underflow | ||
it("should test exit code 9", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"9", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 9, | ||
}); | ||
}); | ||
|
||
// 10: Dictionary error | ||
it("should test exit code 10", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"10", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 10, | ||
}); | ||
}); | ||
|
||
// 11: "Unknown" error | ||
// NOTE: Thrown in various unrelated cases | ||
it("should test exit code 11", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"11", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: 11, | ||
}); | ||
}); | ||
|
||
// 12: Fatal error | ||
// NOTE: thrown by TVM in situations deemed impossible) | ||
|
||
// 13 (actually, -14): Out of gas | ||
it("should test exit code 13", async () => { | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"13", | ||
); | ||
|
||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: -14, | ||
}); | ||
}); | ||
|
||
// 14: Virtualization error | ||
// NOTE: Reserved, but never thrown | ||
}); |
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 @@ | ||
() stack_overflow() impure asm """ | ||
<{ | ||
}>CONT // c | ||
0 SETNUMARGS // c' | ||
2 PUSHINT // c' 2 | ||
SWAP // 2 c' | ||
1 -1 SETCONTARGS | ||
"""; |
Oops, something went wrong.