From 3c9670bfefd71f19bcb9af0002055f2ea5bbde56 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Sat, 10 Feb 2024 15:02:32 -0500 Subject: [PATCH] Create test file which inclues handful of unit tests for "encodeFunction" function --- test/.empty | 0 test/encodeFunction.test.ts | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) delete mode 100644 test/.empty create mode 100644 test/encodeFunction.test.ts diff --git a/test/.empty b/test/.empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/encodeFunction.test.ts b/test/encodeFunction.test.ts new file mode 100644 index 0000000000..d5cdd9b71e --- /dev/null +++ b/test/encodeFunction.test.ts @@ -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' + ); +});