forked from tact-lang/tact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check
repeat
-loop ranges (tact-lang#766)
- Loading branch information
Showing
3 changed files
with
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
contract RepeatRange { | ||
/// To handle deployment | ||
receive() {} | ||
|
||
/// from -2^{256} to 0, including both ends | ||
get fun testIgnoredRange(): Bool { | ||
let counter = 0; | ||
|
||
repeat ((-pow(2, 255)) * 2) { counter += 1 } | ||
repeat (-1) { counter += 1 } | ||
repeat (0) { counter += 1 } | ||
|
||
return counter == 0; | ||
} | ||
|
||
/// from 2^{31} to +∞ — repeat range is too big | ||
get fun testInvalidRange(): Bool { | ||
try { | ||
let counter = 0; | ||
repeat (pow(2, 31)) { counter += 1 } | ||
|
||
return false; | ||
} catch (exitCode) { | ||
return exitCode == 5; | ||
} | ||
} | ||
|
||
/// from 1 to 2^{31} - 1, including both ends | ||
get fun testMinEffectiveRange(): Bool { | ||
let counter = 0; | ||
repeat (1) { counter += 1 } | ||
|
||
return counter == 1; | ||
} | ||
|
||
/// from 1 to 2^{31} - 1, including both ends | ||
receive("testMaxEffectiveRange") { | ||
let counter = pow(2, 31) - 1; | ||
|
||
// This will cause exit code -14 in Compute phase (as expected) | ||
repeat (pow(2, 31) - 1) { counter += 1 } | ||
} | ||
} |
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,57 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { RepeatRange } from "./contracts/output/repeat-range_RepeatRange"; | ||
import "@ton/test-utils"; | ||
|
||
describe("repeat range", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<RepeatRange>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
blockchain.verbosity.print = false; | ||
treasure = await blockchain.treasury("treasure", { | ||
resetBalanceIfZero: true, | ||
}); | ||
|
||
contract = blockchain.openContract(await RepeatRange.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 test repeat range boundaries", async () => { | ||
// ignored range | ||
expect(await contract.getTestIgnoredRange()).toEqual(true); | ||
|
||
// invalid range | ||
expect(await contract.getTestInvalidRange()).toEqual(true); | ||
|
||
// min effective range | ||
expect(await contract.getTestMinEffectiveRange()).toEqual(true); | ||
|
||
// max effective range | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"testMaxEffectiveRange", | ||
); | ||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: false, | ||
exitCode: -14, | ||
}); | ||
}); | ||
}); |
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