feat(test):add more test and remove unused function

datastructure-update
neeboo 5 years ago
parent 09a11f5310
commit 4af0656111
  1. 14
      packages/harmony-crypto/src/keccak256.ts
  2. 55
      packages/harmony-crypto/test/address.test.ts
  3. 38
      packages/harmony-crypto/test/bytes.test.ts
  4. 3098
      packages/harmony-crypto/test/fixtures/hashes.json
  5. 326
      packages/harmony-crypto/test/fixtures/rlpcoder.json
  6. 11
      packages/harmony-crypto/test/keccak256.test.ts
  7. 29
      packages/harmony-crypto/test/keyTool.test.ts
  8. 15
      packages/harmony-crypto/test/rlp.test.ts
  9. 3
      packages/harmony-crypto/test/tsconfig.json
  10. 2
      packages/harmony-crypto/tsconfig.test.json
  11. 12
      packages/harmony-transaction/test/testSign.test.ts
  12. 1
      scripts/jest/jest.src.config.js

@ -11,10 +11,10 @@ export function keccak256(data: Arrayish): string {
throw new Error('arrayify failed'); throw new Error('arrayify failed');
} }
export function sha3_256(data: Arrayish): string { // export function sha3_256(data: Arrayish): string {
const arrayified = arrayify(data); // const arrayified = arrayify(data);
if (arrayified) { // if (arrayified) {
return '0x' + sha3.sha3_256(arrayified); // return '0x' + sha3.sha3_256(arrayified);
} // }
throw new Error('arrayify failed'); // throw new Error('arrayify failed');
} // }

@ -0,0 +1,55 @@
import { getAddress, HarmonyAddress } from '../src/address';
import { randomBytes } from '../src/random';
import { toBech32, fromBech32, HRP, tHRP } from '../src/bech32';
import { toChecksumAddress, isValidChecksumAddress } from '../src/keyTool';
const bytes = randomBytes(20);
const bytesWith0x = '0x' + bytes;
const checksum = toChecksumAddress(bytesWith0x);
const bech32 = toBech32(checksum, HRP);
const bech32Testnet = toBech32(checksum, tHRP);
describe('test address', () => {
it('should test HamonyAddress', () => {
const hAddress = new HarmonyAddress(bytes);
expect(hAddress.basic).toEqual(bytes);
expect(hAddress.basicHex).toEqual(bytesWith0x);
expect(hAddress.checksum).toEqual(checksum);
expect(hAddress.bech32).toEqual(bech32);
expect(hAddress.bech32TestNet).toEqual(bech32Testnet);
expect(getAddress(bytes).basic).toEqual(bytes);
expect(getAddress(bytes).basicHex).toEqual(bytesWith0x);
expect(getAddress(bytes).checksum).toEqual(checksum);
expect(getAddress(bytes).bech32).toEqual(bech32);
expect(getAddress(bytes).bech32TestNet).toEqual(bech32Testnet);
expect(toBech32(checksum)).toEqual(bech32);
expect(fromBech32(bech32, HRP)).toEqual(checksum);
expect(fromBech32(bech32)).toEqual(checksum);
expect(fromBech32(bech32Testnet, tHRP)).toEqual(checksum);
expect(HarmonyAddress.isValidBasic(bytes)).toEqual(true);
expect(HarmonyAddress.isValidChecksum(checksum)).toEqual(true);
expect(HarmonyAddress.isValidBech32(bech32)).toEqual(true);
expect(HarmonyAddress.isValidBech32TestNet(bech32Testnet)).toEqual(true);
expect(isValidChecksumAddress(checksum)).toEqual(true);
try {
// tslint:disable-next-line: no-unused-expression
getAddress('111').checksum;
} catch (error) {
expect(error.message).toEqual(`"111" is an invalid address format`);
}
try {
fromBech32(bech32, tHRP);
} catch (error) {
expect(error.message).toEqual(`Expected hrp to be ${tHRP} but got ${HRP}`);
}
try {
fromBech32(checksum, tHRP);
} catch (error) {
expect(error.message).toEqual(`Invalid bech32 address`);
}
try {
toBech32('111', tHRP);
} catch (error) {
expect(error.message).toEqual(`Invalid address format.`);
}
});
});

@ -0,0 +1,38 @@
import * as bytes from '../src/bytes';
describe('Bytes', () => {
it('hexlify on string of unsafe number', () => {
[9007199254740991, 9985956830000000000].forEach((value) => {
try {
bytes.hexlify(value);
} catch (error) {
expect(error.code).toEqual('NUMERIC_FAULT');
expect(error.fault).toEqual('out-of-safe-range');
}
});
});
it('splits a canonical signature', () => {
const r = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
const s = '0xcafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7e';
for (let v = 27; v <= 28; v++) {
const signature = bytes.concat([r, s, [v]]);
const sig = bytes.splitSignature(signature);
expect(sig.r).toEqual(r);
expect(sig.s).toEqual(s);
expect(sig.v).toEqual(v);
}
});
it('splits a legacy signature', () => {
const r = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
const s = '0xcafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7e';
for (let v = 27; v <= 28; v++) {
const signature = bytes.concat([r, s, [v - 27]]);
const sig = bytes.splitSignature(signature);
expect(sig.r).toEqual(r);
expect(sig.s).toEqual(s);
expect(sig.v).toEqual(v);
}
});
});

File diff suppressed because it is too large Load Diff

@ -0,0 +1,326 @@
[
{
"name": "arrayInside",
"decoded": [
"0x48656c6c6f20576f726c64",
[
"0x48656c6c6f20576f726c64",
"0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2e",
["0x48656c6c6f20576f726c64", ["0x48656c6c6f20576f726c64"]]
],
"0x48656c6c6f20576f726c64"
],
"encoded": "0xf903948b48656c6c6f20576f726c64f903798b48656c6c6f20576f726c64b903504c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2ed98b48656c6c6f20576f726c64cc8b48656c6c6f20576f726c648b48656c6c6f20576f726c64"
},
{
"name": "arrayLong2",
"decoded": ["0x48656c6c6f20576f726c64", "0x48656c6c6f20576f726c64"],
"encoded": "0xd88b48656c6c6f20576f726c648b48656c6c6f20576f726c64"
},
{
"name": "arrayShort2",
"decoded": ["0x48656c6c6f20576f726c64", "0x48656c6c6f20576f726c64"],
"encoded": "0xd88b48656c6c6f20576f726c648b48656c6c6f20576f726c64"
},
{
"name": "arrayShortLong",
"decoded": [
"0x48656c6c6f20576f726c64",
"0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2e"
],
"encoded": "0xf9035f8b48656c6c6f20576f726c64b903504c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2e"
},
{
"name": "arrayWithNullString",
"decoded": ["0x"],
"encoded": "0xc180"
},
{
"name": "arrayWithNullString3",
"decoded": ["0x", "0x", "0x"],
"encoded": "0xc3808080"
},
{
"name": "assorted",
"decoded": [
[
"0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2e"
],
["0x80"],
"0x02",
["0x7e"],
[["0x48656c6c6f20576f726c64"], ["0xff"]]
],
"encoded": "0xf9036df90353b903504c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e204d616563656e617320616c697175657420646f6c6f72206e756c6c612c206e65632074696e636964756e74206d61737361206d6f6c6c69732061742e20496e206d6f6c6c697320626c616e646974206475692c20696420656c656d656e74756d2065726f7320696163756c69732075742e2050686173656c6c7573206c6f626f727469732c20697073756d2071756973206665726d656e74756d206d6f6c6c69732c2065726f73206e69736c2072757472756d206475692c207574206c7563747573206c656f207475727069732075742061756775652e204675736365206f64696f207475727069732c2070686172657472612061742076656e656e6174697320696e2c20636f6e76616c6c69732071756973206e6962682e204475697320617563746f722c2061756775652073697420616d65742076656e656e617469732076756c7075746174652c206e69736c206e6962682066657567696174206d61757269732c206964206d6f6c65737469652061756775652064756920736564206a7573746f2e2053757370656e646973736520697073756d206d61757269732c207361676974746973206e6563206c616f72656574206e6f6e2c20656765737461732076656c206e6962682e2050656c6c656e74657371756520616c697175657420616363756d73616e2076656c697420696e20646170696275732e2041656e65616e206567657420617567756520617263752e205574206d6f6c6c6973206c656f206d692c206575206c75637475732065726f7320666163696c697369732065752e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e2053757370656e6469737365206566666963697475722c206a7573746f206120766f6c75747061742074656d706f722c206e696268206c6967756c612066696e69627573207475727069732c20657520666163696c6973697320746f72746f722076656c6974206e65632076656c69742e2044756973206e65632074656d706f72206c65637475732c206e6f6e20636f6e76616c6c69732073656d2ec2818002c17ed0cc8b48656c6c6f20576f726c64c281ff"
},
{
"name": "assortedSingle1",
"decoded": ["0x02", "0x7f", "0x80", "0xff", ["0x7e", "0x02"]],
"encoded": "0xc9027f818081ffc27e02"
},
{
"name": "assortedSingle2",
"decoded": [["0x02", "0x02"], ["0xff", "0xff", "0xff"]],
"encoded": "0xcac20202c681ff81ff81ff"
},
{
"name": "emptyArray",
"decoded": [],
"encoded": "0xc0"
},
{
"name": "nullString",
"decoded": "0x",
"encoded": "0x80"
},
{
"name": "ones_1",
"decoded": "0x01",
"encoded": "0x01"
},
{
"name": "ones_100",
"decoded": "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb86401010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_1000",
"decoded": "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb903e801010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_15",
"decoded": "0x010101010101010101010101010101",
"encoded": "0x8f010101010101010101010101010101"
},
{
"name": "ones_16",
"decoded": "0x01010101010101010101010101010101",
"encoded": "0x9001010101010101010101010101010101"
},
{
"name": "ones_17",
"decoded": "0x0101010101010101010101010101010101",
"encoded": "0x910101010101010101010101010101010101"
},
{
"name": "ones_2",
"decoded": "0x0101",
"encoded": "0x820101"
},
{
"name": "ones_2049",
"decoded": "0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb90801010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_3",
"decoded": "0x010101",
"encoded": "0x83010101"
},
{
"name": "ones_31",
"decoded": "0x01010101010101010101010101010101010101010101010101010101010101",
"encoded": "0x9f01010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_32",
"decoded": "0x0101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xa00101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_33",
"decoded": "0x010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xa1010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_4",
"decoded": "0x01010101",
"encoded": "0x8401010101"
},
{
"name": "ones_53",
"decoded": "0x0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb50101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_54",
"decoded": "0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb6010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_55",
"decoded": "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb701010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_56",
"decoded": "0x0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb8380101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_57",
"decoded": "0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb839010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_58",
"decoded": "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"encoded": "0xb83a01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"name": "ones_7",
"decoded": "0x01010101010101",
"encoded": "0x8701010101010101"
},
{
"name": "ones_8",
"decoded": "0x0101010101010101",
"encoded": "0x880101010101010101"
},
{
"name": "ones_9",
"decoded": "0x010101010101010101",
"encoded": "0x89010101010101010101"
},
{
"name": "singleHigh",
"decoded": "0xff",
"encoded": "0x81ff"
},
{
"name": "singleLessMed",
"decoded": "0x7e",
"encoded": "0x7e"
},
{
"name": "singleLow",
"decoded": "0x02",
"encoded": "0x02"
},
{
"name": "singleMed",
"decoded": "0x7f",
"encoded": "0x7f"
},
{
"name": "singleMoreMed",
"decoded": "0x80",
"encoded": "0x8180"
},
{
"name": "threeSet",
"decoded": [[], [[]], [[[]]]],
"encoded": "0xc6c0c1c0c2c1c0"
},
{
"name": "zeros_1",
"decoded": "0x00",
"encoded": "0x00"
},
{
"name": "zeros_100",
"decoded": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb86400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_1000",
"decoded": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb903e800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_15",
"decoded": "0x000000000000000000000000000000",
"encoded": "0x8f000000000000000000000000000000"
},
{
"name": "zeros_16",
"decoded": "0x00000000000000000000000000000000",
"encoded": "0x9000000000000000000000000000000000"
},
{
"name": "zeros_17",
"decoded": "0x0000000000000000000000000000000000",
"encoded": "0x910000000000000000000000000000000000"
},
{
"name": "zeros_2",
"decoded": "0x0000",
"encoded": "0x820000"
},
{
"name": "zeros_2049",
"decoded": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb90801000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_3",
"decoded": "0x000000",
"encoded": "0x83000000"
},
{
"name": "zeros_31",
"decoded": "0x00000000000000000000000000000000000000000000000000000000000000",
"encoded": "0x9f00000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_32",
"decoded": "0x0000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xa00000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_33",
"decoded": "0x000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xa1000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_4",
"decoded": "0x00000000",
"encoded": "0x8400000000"
},
{
"name": "zeros_53",
"decoded": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_54",
"decoded": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_55",
"decoded": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_56",
"decoded": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb8380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_57",
"decoded": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb839000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_58",
"decoded": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"encoded": "0xb83a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"name": "zeros_7",
"decoded": "0x00000000000000",
"encoded": "0x8700000000000000"
},
{
"name": "zeros_8",
"decoded": "0x0000000000000000",
"encoded": "0x880000000000000000"
},
{
"name": "zeros_9",
"decoded": "0x000000000000000000",
"encoded": "0x89000000000000000000"
}
]

@ -0,0 +1,11 @@
import * as hash from '../src/keccak256';
import hashes from './fixtures/hashes.json';
describe('should test keccak256', () => {
it('should test keccak256 hashing', () => {
hashes.forEach((testcase) => {
expect(hash.keccak256(testcase.data)).toEqual(testcase.keccak256);
});
});
});

@ -0,0 +1,29 @@
import * as keys from '../src/keyTool';
import { isPrivateKey, isAddress, isPublicKey } from '@harmony-js/utils';
describe('test keyTools', () => {
it('test keygen', () => {
const prv = keys.generatePrivateKey();
const pub = keys.getPubkeyFromPrivateKey(prv);
const addr = keys.getAddressFromPublicKey(pub);
const addrPrv = keys.getAddressFromPrivateKey(prv);
expect(isPrivateKey(prv)).toEqual(true);
expect(isPublicKey(pub)).toEqual(true);
expect(isAddress(addr)).toEqual(true);
expect(isAddress(addrPrv)).toEqual(true);
expect(addr).toEqual(addrPrv);
});
it('should test sign', () => {
const unsigned = '0xdc80808080809401234567890123456789012345678901234567898080';
const privateKey = '0x0123456789012345678901234567890123456789012345678901234567890123';
const pub = keys.getPubkeyFromPrivateKey(privateKey);
const signature = keys.sign(unsigned, privateKey);
expect(keys.verifySignature(unsigned, signature, pub)).toEqual(true);
try {
keys.sign(unsigned, '111');
} catch (error) {
expect(error.message).toEqual(`111 is not PrivateKey`);
}
});
});

@ -0,0 +1,15 @@
import * as rlp from '../src/rlp';
import cases from './fixtures/rlpcoder.json';
describe('rlp', () => {
it('should test rlp encoder', () => {
cases.forEach((testcase) => {
expect(rlp.encode(testcase.decoded)).toEqual(testcase.encoded);
});
});
it('should test rlp decoder', () => {
cases.forEach((testcase) => {
expect(rlp.decode(testcase.encoded)).toEqual(testcase.decoded);
});
});
});

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.test.json"
}

@ -1,5 +1,5 @@
{ {
"extends": "../../tsconfig.test.json", "extends": "../../tsconfig.test.json",
"include": ["src", "__test__", "../../typings/**/*.d.ts"], "include": ["src", "test", "../../typings/**/*.d.ts"],
"references": [] "references": []
} }

@ -52,6 +52,17 @@ describe('test sign tranction', () => {
expect(isValidAddress(address)).toEqual(true); expect(isValidAddress(address)).toEqual(true);
expect(address).toEqual(vector.accountAddress); expect(address).toEqual(vector.accountAddress);
expect(getAddress(address).bech32).toEqual(vector.accountBech32Address); expect(getAddress(address).bech32).toEqual(vector.accountBech32Address);
expect(Transaction.normalizeAddress(getAddress(address).bech32)).toEqual(
getAddress(address).checksum,
);
expect(Transaction.normalizeAddress(getAddress(address).bech32TestNet)).toEqual(
getAddress(address).checksum,
);
try {
Transaction.normalizeAddress(getAddress(address).basicHex);
} catch (error) {
expect(error.message).toEqual('Address format is not supported');
}
const transaction: Transaction = new Transaction( const transaction: Transaction = new Transaction(
{ {
@ -65,6 +76,7 @@ describe('test sign tranction', () => {
hmyMessenger, hmyMessenger,
TxStatus.INTIALIZED, TxStatus.INTIALIZED,
); );
transaction.setMessenger(hmyMessenger);
const unsigned = transaction.getRLPUnsigned(); const unsigned = transaction.getRLPUnsigned();

@ -43,6 +43,7 @@ const config = {
'packages/harmony-crypto/src/**/*.ts', 'packages/harmony-crypto/src/**/*.ts',
'packages/harmony-transaction/src/**/*.ts', 'packages/harmony-transaction/src/**/*.ts',
'packages/harmony-staking/src/**/*.ts', 'packages/harmony-staking/src/**/*.ts',
'packages/harmony-contract/src/**/*.ts',
], ],
// timers: 'fake', // timers: 'fake',
setupFiles: ['<rootDir>/scripts/jest/jest.setup.js'], setupFiles: ['<rootDir>/scripts/jest/jest.setup.js'],

Loading…
Cancel
Save