Skip to content

Commit

Permalink
Merge pull request #1935 from aeternity/feature/bytes_any_size
Browse files Browse the repository at this point in the history
test(contract): ensure bytes any size works
  • Loading branch information
davidyuk authored Jan 25, 2024
2 parents 15534df + 5b70c0e commit 2d4734f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"SDK"
],
"dependencies": {
"@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#7cce0a6d23ec0ba5f23f46acf9d4254a9346c9c9",
"@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#aens_v2",
"@aeternity/argon2": "^0.0.1",
"@aeternity/uuid": "^0.0.1",
"@azure/core-client": "1.6.0",
Expand Down
17 changes: 17 additions & 0 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ contract StateContract =
entrypoint hashFn(s: hash): hash = s
entrypoint signatureFn(s: signature): signature = s
entrypoint bytesFn(s: bytes(32)): bytes(32) = s
entrypoint bytesAnySizeFn(s: bytes) = s
entrypoint bitsFn(s: bits): bits = s
Expand Down Expand Up @@ -153,6 +154,7 @@ interface TestContractApi extends ContractMethodsBase {
hashFn: (s: Uint8Array | string) => Uint8Array;
signatureFn: (s: Uint8Array | string) => Uint8Array;
bytesFn: (s: Uint8Array | string) => Uint8Array;
bytesAnySizeFn: (s: Uint8Array | string) => Uint8Array;

bitsFn: (s: InputNumber) => bigint;

Expand Down Expand Up @@ -1041,6 +1043,21 @@ describe('Contract instance', () => {
});
});

describe('Bytes any size', () => {
it('Invalid type', async () => {
await expect(testContract.bytesAnySizeFn({} as any))
.to.be.rejectedWith('Should be one of: Array, ArrayBuffer, hex string, Number, BigInt; got [object Object] instead');
});

it('Valid', async () => {
const decoded = Buffer.from('0xdeadbeef', 'hex');
const { decodedResult: hashAsBuffer } = await testContract.bytesAnySizeFn(decoded);
const { decodedResult: hashAsHex } = await testContract.bytesAnySizeFn(decoded.toString('hex'));
expect(hashAsBuffer).to.be.eql(decoded);
expect(hashAsHex).to.be.eql(decoded);
});
});

describe('Bits', () => {
it('Invalid', async () => {
await expect(testContract.bitsFn({} as any))
Expand Down

0 comments on commit 2d4734f

Please sign in to comment.