-
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.
- Loading branch information
Showing
18 changed files
with
101 additions
and
63 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
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
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,38 @@ | ||
import { toNano } from "@ton/core"; | ||
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; | ||
import { AsCommentTester } from "./contracts/output/as-comment_AsCommentTester"; | ||
import "@ton/test-utils"; | ||
|
||
describe("asComment", () => { | ||
let blockchain: Blockchain; | ||
let treasure: SandboxContract<TreasuryContract>; | ||
let contract: SandboxContract<AsCommentTester>; | ||
|
||
beforeEach(async () => { | ||
blockchain = await Blockchain.create(); | ||
blockchain.verbosity.print = false; | ||
treasure = await blockchain.treasury("treasure"); | ||
contract = blockchain.openContract(await AsCommentTester.fromInit()); | ||
|
||
const result = await contract.send( | ||
treasure.getSender(), | ||
{ | ||
value: toNano("10"), | ||
}, | ||
null, | ||
); | ||
|
||
expect(result.transactions).toHaveTransaction({ | ||
from: treasure.address, | ||
to: contract.address, | ||
success: true, | ||
deploy: true, | ||
}); | ||
}); | ||
|
||
it("should calculate asComment in compile-time as in runtime", async () => { | ||
expect(await contract.getConstantCell()).toEqualCell( | ||
await contract.getAsCommentRuntimeCell("hello world"), | ||
); | ||
}); | ||
}); |
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 @@ | ||
const ConstantCell: Cell = "hello world".asComment(); | ||
|
||
contract AsCommentTester { | ||
receive() {} | ||
|
||
get fun constantCell(): Cell { | ||
return ConstantCell; | ||
} | ||
|
||
get fun asCommentRuntimeCell(val: String): Cell { | ||
return val.asComment(); | ||
} | ||
} |
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,12 @@ | ||
import { crc32 } from "./crc32"; | ||
|
||
describe("crc32", () => { | ||
it("crc32 is correctly calculated from the string", () => { | ||
expect(crc32("")).toBe(0); | ||
expect(crc32("Hello Tact")).toBe(-1612685692); | ||
expect(crc32("Привет Tact")).toBe(-1470995533); | ||
expect(crc32("👋 Tact")).toBe(1855222621); | ||
expect(crc32("\u0000")).toBe(-771559539); | ||
expect(crc32("⚡")).toBe(2136484914); | ||
}); | ||
}); |
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,28 @@ | ||
function makeCRC32Table(polynomial: number): Int32Array { | ||
let c: number; | ||
const table = new Int32Array(256); | ||
for (let n = 0; n < table.length; n++) { | ||
c = n; | ||
for (let k = 0; k < 8; k++) { | ||
c = c & 1 ? (c >>> 1) ^ polynomial : c >>> 1; | ||
} | ||
table[n] = c; | ||
} | ||
return table; | ||
} | ||
|
||
// Reversed polynomial of ISO3309 CRC32 | ||
const CRC32C_TABLE = makeCRC32Table(0xedb88320); | ||
|
||
export function crc32(data: string | Uint8Array): number { | ||
if (typeof data === "string") { | ||
data = new TextEncoder().encode(data); | ||
} | ||
|
||
let crc = 0xffffffff; | ||
for (const byte of data) { | ||
crc = CRC32C_TABLE[(crc ^ byte) & 0xff]! ^ (crc >>> 8); | ||
} | ||
|
||
return crc ^ 0xffffffff; | ||
} |
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