Skip to content

Commit

Permalink
chore: purge testcases package (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Dec 14, 2023
1 parent dd31612 commit a4aec14
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 690 deletions.
2 changes: 2 additions & 0 deletions .changeset/hip-humans-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 0 additions & 3 deletions packages/address/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,5 @@
"@fuel-ts/versions": "workspace:*",
"bech32": "^2.0.0",
"ethers": "^6.7.1"
},
"devDependencies": {
"@fuel-ts/testcases": "workspace:*"
}
}
27 changes: 15 additions & 12 deletions packages/address/src/address.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FuelError } from '@fuel-ts/errors';
import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
import type { AssetId, B256AddressEvm, Bech32Address, EvmAddress } from '@fuel-ts/interfaces';
import signMessageTest from '@fuel-ts/testcases/src/signMessage.json';

import Address from './address';
import * as utils from './utils';

const PUBLIC_KEY = signMessageTest.publicKey;
const PUBLIC_KEY =
'0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e';
const ADDRESS_B256 = '0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a';
const ADDRESS_B256_EVM_PADDED: B256AddressEvm =
'0x00000000000000000000000007a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a';
Expand All @@ -22,6 +22,9 @@ const ADDRESS_BYTES = [
226, 174, 6, 54, 251, 51, 211, 203, 42, 158, 74,
];

const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf';
const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';

describe('Address utils', () => {
test('fromBech32 (bech32 to decoded bech32)', () => {
const result = utils.fromBech32(ADDRESS_BECH32);
Expand Down Expand Up @@ -250,8 +253,8 @@ describe('Address class', () => {
test('create an Address class using public key', () => {
const address = Address.fromPublicKey(PUBLIC_KEY);

expect(address.toAddress()).toEqual(signMessageTest.address);
expect(address.toB256()).toEqual(signMessageTest.b256Address);
expect(address.toAddress()).toEqual(expectedAddress);
expect(address.toB256()).toEqual(expectedB256Address);
});

test('create an Address class using invalid public key (no hex prefix)', async () => {
Expand Down Expand Up @@ -282,8 +285,8 @@ describe('Address class', () => {
});

test('when parsing to JSON it should show the bech32 address', () => {
const result = Address.fromB256(signMessageTest.b256Address);
expect(JSON.stringify(result)).toEqual(`"${signMessageTest.address}"`);
const result = Address.fromB256(expectedB256Address);
expect(JSON.stringify(result)).toEqual(`"${expectedAddress}"`);
});

test('valueOf matches toString', () => {
Expand All @@ -295,20 +298,20 @@ describe('Address class', () => {
test('create an Address class fromDynamicInput [public key]', () => {
const address = Address.fromDynamicInput(PUBLIC_KEY);

expect(address.toAddress()).toEqual(signMessageTest.address);
expect(address.toB256()).toEqual(signMessageTest.b256Address);
expect(address.toAddress()).toEqual(expectedAddress);
expect(address.toB256()).toEqual(expectedB256Address);
});

test('create an Address class fromDynamicInput [b256Address]', () => {
const address = Address.fromDynamicInput(signMessageTest.b256Address);
const address = Address.fromDynamicInput(expectedB256Address);

expect(address.toAddress()).toEqual(signMessageTest.address);
expect(address.toAddress()).toEqual(expectedAddress);
});

test('create an Address class fromDynamicInput [bech32Address]', () => {
const address = Address.fromDynamicInput(signMessageTest.address);
const address = Address.fromDynamicInput(expectedAddress);

expect(address.toB256()).toEqual(signMessageTest.b256Address);
expect(address.toB256()).toEqual(expectedB256Address);
});

test('create an Address class fromDynamicInput [evmAddress]', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/hasher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ramda": "^0.29.0"
},
"devDependencies": {
"@fuel-ts/testcases": "workspace:*",
"@types/ramda": "^0.29.3"
}
}
6 changes: 3 additions & 3 deletions packages/hasher/src/hasher.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import signMessageTest from '@fuel-ts/testcases/src/signMessage.json';

import { hashMessage, hash } from './hasher';

describe('Hasher', () => {
it('Hash message', () => {
expect(hashMessage(signMessageTest.message)).toEqual(signMessageTest.hashedMessage);
const message = 'my message';
const hashedMessage = '0xea38e30f75767d7e6c21eba85b14016646a3b60ade426ca966dac940a5db1bab';
expect(hashMessage(message)).toEqual(hashedMessage);
});

it('Hash "20"', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ethers": "^6.7.1"
},
"devDependencies": {
"@fuel-ts/testcases": "workspace:*",
"@types/elliptic": "^6.4.14"
}
}
46 changes: 27 additions & 19 deletions packages/signer/src/signer.test.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
import signMessageTest from '@fuel-ts/testcases/src/signMessage.json';
import { getBytesCopy, sha256 } from 'ethers';

import Signer from './signer';

describe('Signer', () => {
const expectedPrivateKey = '0x5f70feeff1f229e4a95e1056e8b4d80d0b24b565674860cc213bdb07127ce1b1';
const expectedPublicKey =
'0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e';
const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf';
const expectedMessage = 'my message';
const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';
const expectedSignedMessage =
'0x8eeb238db1adea4152644f1cd827b552dfa9ab3f4939718bb45ca476d167c6512a656f4d4c7356bfb9561b14448c230c6e7e4bd781df5ee9e5999faa6495163d';

it('Initialize publicKey and address for new signer instance', () => {
const signer = new Signer(signMessageTest.privateKey);
const signer = new Signer(expectedPrivateKey);

expect(signer.privateKey).toEqual(signMessageTest.privateKey);
expect(signer.publicKey).toEqual(signMessageTest.publicKey);
expect(signer.address.toAddress()).toEqual(signMessageTest.address);
expect(signer.address.toB256()).toEqual(signMessageTest.b256Address);
expect(signer.privateKey).toEqual(expectedPrivateKey);
expect(signer.publicKey).toEqual(expectedPublicKey);
expect(signer.address.toAddress()).toEqual(expectedAddress);
expect(signer.address.toB256()).toEqual(expectedB256Address);
});

it('Initialize publicKey and address for new signer instance with byte array', () => {
const signer = new Signer(getBytesCopy(signMessageTest.privateKey));
const signer = new Signer(getBytesCopy(expectedPrivateKey));

expect(signer.privateKey).toEqual(signMessageTest.privateKey);
expect(signer.publicKey).toEqual(signMessageTest.publicKey);
expect(signer.address.toAddress()).toEqual(signMessageTest.address);
expect(signer.address.toB256()).toEqual(signMessageTest.b256Address);
expect(signer.privateKey).toEqual(expectedPrivateKey);
expect(signer.publicKey).toEqual(expectedPublicKey);
expect(signer.address.toAddress()).toEqual(expectedAddress);
expect(signer.address.toB256()).toEqual(expectedB256Address);
});

it('Sign message', () => {
const signer = new Signer(signMessageTest.privateKey);
const signedMessage = signer.sign(sha256(Buffer.from(signMessageTest.message)));
const signer = new Signer(expectedPrivateKey);
const signedMessage = signer.sign(sha256(Buffer.from(expectedMessage)));

expect(signedMessage).toEqual(signMessageTest.signedMessage);
expect(signedMessage).toEqual(expectedSignedMessage);
});

it('Recover publicKey and address from signed message', () => {
const signer = new Signer(signMessageTest.privateKey);
const hashedMessage = sha256(Buffer.from(signMessageTest.message));
const signer = new Signer(expectedPrivateKey);
const hashedMessage = sha256(Buffer.from(expectedMessage));
const signedMessage = signer.sign(hashedMessage);

const recoveredAddress = Signer.recoverAddress(hashedMessage, signedMessage);

expect(recoveredAddress.toAddress()).toEqual(signMessageTest.address);
expect(recoveredAddress.toB256()).toEqual(signMessageTest.b256Address);
expect(recoveredAddress.toAddress()).toEqual(expectedAddress);
expect(recoveredAddress.toB256()).toEqual(expectedB256Address);
});

it('Extend publicKey from compact publicKey', () => {
const signer = new Signer(signMessageTest.privateKey);
const signer = new Signer(expectedPrivateKey);

expect(signer.publicKey).toEqual(Signer.extendPublicKey(signer.compressedPublicKey));
});
Expand Down
Loading

0 comments on commit a4aec14

Please sign in to comment.