-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 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,41 @@ | ||
contract RepeatRange { | ||
/// Effective range counter | ||
effCounter: Int = 0; | ||
|
||
/// To handle deployment | ||
receive() {} | ||
|
||
/// from -2^{256} to 0, including both ends | ||
get fun testIgnoredRange(): Int { | ||
let counter = 0; | ||
|
||
repeat ((-pow(2, 255)) * 2) { counter += 1 } | ||
repeat (-1) { counter += 1 } | ||
repeat (0) { counter += 1 } | ||
|
||
return counter; // 0, if things go right | ||
} | ||
|
||
/// from 2^{31} to +∞ — repeat range is too big | ||
get fun testInvalidRange(): Int { | ||
let caseCounter = 0; | ||
|
||
try { | ||
repeat (pow(2, 31)) { caseCounter -= 1 } | ||
} catch (_) { caseCounter += 1 } | ||
|
||
return caseCounter; // 1, if things go right | ||
} | ||
|
||
/// from 1 to 2^{31} - 1, including both ends | ||
receive("effectiveRange") { | ||
self.effCounter = 0; | ||
|
||
repeat (1) { self.effCounter += 1} | ||
repeat (pow(2, 31) - 1) { self.effCounter += 1} | ||
} | ||
|
||
get fun effectiveRangeCounter(): Int { | ||
return self.effCounter; // 2^{31}, if ran after receiving "effectiveRange" msg | ||
} | ||
} |
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,67 @@ | ||
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 () => { | ||
const LARGE_SUM = 10_000_000_000n; | ||
|
||
blockchain = await Blockchain.create(); | ||
treasure = await blockchain.treasury("treasure", { | ||
balance: LARGE_SUM, | ||
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, | ||
}); | ||
|
||
const topUpResult = await treasure.send({ | ||
to: contract.address, | ||
value: LARGE_SUM, | ||
}); | ||
|
||
expect(topUpResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
}); | ||
}); | ||
|
||
it("should test repeat range boundaries", async () => { | ||
// ignored range | ||
expect(await contract.getTestIgnoredRange()).toEqual(0n); | ||
|
||
// invalid range | ||
expect(await contract.getTestInvalidRange()).toEqual(1n); | ||
|
||
// effective range | ||
const sendResult = await contract.send( | ||
treasure.getSender(), | ||
{ value: toNano("10") }, | ||
"effectiveRange", | ||
); | ||
expect(sendResult.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
}); | ||
expect(await contract.getEffectiveRangeCounter()).toEqual(2n ** 31n); | ||
}); | ||
}); |
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