From 8083b33d97203ea82d9b288ae4b7aa1562c6a2fa Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:44:47 +0100 Subject: [PATCH] test: statically known strings and runtime known strings --- package.json | 2 +- src/test/compilation-failed/abi-global-errors.spec.ts | 2 -- src/test/e2e-emulated/contracts/intrinsics.tact | 10 +++++++++- src/test/e2e-emulated/intrinsics.spec.ts | 10 ++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 11947028a..d885a51ab 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/test/compilation-failed/abi-global-errors.spec.ts b/src/test/compilation-failed/abi-global-errors.spec.ts index f565c3eed..3f9808dfc 100644 --- a/src/test/compilation-failed/abi-global-errors.spec.ts +++ b/src/test/compilation-failed/abi-global-errors.spec.ts @@ -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", diff --git a/src/test/e2e-emulated/contracts/intrinsics.tact b/src/test/e2e-emulated/contracts/intrinsics.tact index d3ef60d6f..5f45cd563 100644 --- a/src/test/e2e-emulated/contracts/intrinsics.tact +++ b/src/test/e2e-emulated/contracts/intrinsics.tact @@ -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()); } @@ -231,4 +239,4 @@ contract IntrinsicsTester { get fun getRawSlice24(): Slice { return self.v; } -} \ No newline at end of file +} diff --git a/src/test/e2e-emulated/intrinsics.spec.ts b/src/test/e2e-emulated/intrinsics.spec.ts index eebb4a877..e77224072 100644 --- a/src/test/e2e-emulated/intrinsics.spec.ts +++ b/src/test/e2e-emulated/intrinsics.spec.ts @@ -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(