Skip to content

Commit

Permalink
test: statically known strings and runtime known strings
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Nov 12, 2024
1 parent de62a93 commit 8083b33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1",
"lint": "yarn eslint .",
"lint:schema": "ajv validate -s schemas/configSchema.json -d tact.config.json",
"fmt": "yarn prettier -w .",
"fmt": "yarn prettier -l -w .",
"fmt:check": "yarn prettier --check .",
"spell": "yarn cspell --no-progress \"**\"",
"knip": "knip",
Expand Down
2 changes: 0 additions & 2 deletions src/test/compilation-failed/abi-global-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ describe("abi/global.ts errors", () => {
__DANGER_resetNodeId();
});

// TODO: fixme

itShouldNotCompile({
testName: "sha256-expects-string-or-slice",
errorMessage: "sha256 expects string or slice argument",
Expand Down
10 changes: 9 additions & 1 deletion src/test/e2e-emulated/contracts/intrinsics.tact
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ contract IntrinsicsTester {
return sha256(src);
}

get fun getHashLongComptime(): Int {
return sha256("------------------------------------------------------------------------------------------------------------------------------129");
}

get fun getHashLongRuntime(src: String): Int {
return sha256(src);
}

receive("emit_1") {
emit("Hello world".asComment());
}
Expand Down Expand Up @@ -231,4 +239,4 @@ contract IntrinsicsTester {
get fun getRawSlice24(): Slice {
return self.v;
}
}
}
10 changes: 10 additions & 0 deletions src/test/e2e-emulated/intrinsics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe("intrinsics", () => {
),
).toBe(sha256("sometest"));
expect(await contract.getGetHash4("wallet")).toBe(sha256("wallet"));
const longString =
"------------------------------------------------------------------------------------------------------------------------------129";
expect(await contract.getGetHashLongComptime()).toBe(
sha256(longString),
);
// NOTE: The discrepancy here is expected, since SHA256U operates only on the first 128 bytes
expect(
(await contract.getGetHashLongRuntime(longString)) !==
sha256(longString),
).toBe(true);

// Check `slice`
expect(
Expand Down

0 comments on commit 8083b33

Please sign in to comment.