Skip to content

Commit

Permalink
Create test file which inclues handful of unit tests for "encodeFunct…
Browse files Browse the repository at this point in the history
…ion" function
  • Loading branch information
adamgall committed Feb 10, 2024
1 parent eba97cd commit 3c9670b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Empty file removed test/.empty
Empty file.
42 changes: 42 additions & 0 deletions test/encodeFunction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect, test } from 'vitest';
import { encodeFunction } from '../src/utils/crypto';

test('Function encoding with no parameters', () => {
expect(encodeFunction('foo')).toEqual('0xc2985578');
});

test('Function encoding with [boolean=true]', () => {
expect(encodeFunction('foo', 'bool', 'true')).toEqual(
'0x455575780000000000000000000000000000000000000000000000000000000000000001'
);
});

// test('Function encoding with [boolean=false]', () => {
// expect(encodeFunction('foo', 'bool', 'false')).toEqual(
// '0x455575780000000000000000000000000000000000000000000000000000000000000000'
// );
// });

test('Function encoding with [uint=0]', () => {
expect(encodeFunction('foo', 'uint', '0')).toEqual(
'0x2fbebd380000000000000000000000000000000000000000000000000000000000000000'
);
});

test('Function encoding with [uint256=0]', () => {
expect(encodeFunction('foo', 'uint256', '0')).toEqual(
'0x2fbebd380000000000000000000000000000000000000000000000000000000000000000'
);
});

test('Function encoding with [uint8=0]', () => {
expect(encodeFunction('foo', 'uint8', '0')).toEqual(
'0x11602fb30000000000000000000000000000000000000000000000000000000000000000'
);
});

test('Function encoding with [uint8=0]', () => {
expect(encodeFunction('foo', 'uint8', '100')).toEqual(
'0x11602fb30000000000000000000000000000000000000000000000000000000000000064'
);
});

0 comments on commit 3c9670b

Please sign in to comment.