parent
8c709e0e1e
commit
299af73fe5
@ -1,114 +1,114 @@ |
||||
{ |
||||
"transactions": [ |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x0", |
||||
"value": "0x186a0", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8698085174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830186a0801ca06d9f530844b9fd5ad649c9151a53e104e9db9bfe41d68c3db7c1ea4e053e0c50a02ebd5d15d84e01232d3d933806c79c09f4df7be959b2883a0f54f085f0737e43" |
||||
"rawTransaction": "0xf8698085174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830186a08027a0ab8229ff5d5240948098f26372eaed9ab2e9be23e8594b08e358ca56a47f8ae9a0084e5c4d1fec496af444423d8a714f65c079260ff01a1be1de7005dd424adf44" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x1", |
||||
"value": "0x30d40", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690185174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee5283030d40801ba0ea2ad64ff72be2ea7f40b406a8ded60a74b03cc5209d0d3f9c7779daf1bb576ba01cbd1885f66c1f0bb2bc06c7ca40295b5bb1ec7cf0ebe7f5ec53fbfb29bc0373" |
||||
"rawTransaction": "0xf8690185174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee5283030d408028a06c6a5900a44c13c4011ecf48d3149f7114e81d168e11422ce157475053083e94a039ce7ff13a2b79a81e98fb035a4068de54477d4bc671f4695fbd42f416a74cc3" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x2", |
||||
"value": "0x493e0", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690285174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830493e0801ba05e5f8867869b4375a75baa71ed1e5871684cddd0bbe89dbe161e32819585652ea05d4de4b01a93d0c475c21b6f1bfe91509ab74cc86f6a6211dd76116ae0ba0ff3" |
||||
"rawTransaction": "0xf8690285174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830493e08028a0ccc0c2abb00a3133c570cea9281f6a134aa9e3b287b64ec42b608102d70a3f97a02418b19b7b567e6bdfbf49afb6b0980ee16fcf199ef587b62ac2187dd966868f" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x3", |
||||
"value": "0x61a80", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690385174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee5283061a80801ba00aedf5e3b2930da417576909e6567f1745fc90de1d0faac043b9853f2108ec6ca04be11e35cf2c0a70fb3b95628f743ca6491b52f8668b030d173bb949570e9965" |
||||
"rawTransaction": "0xf8690385174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee5283061a808027a054705b19391ca26d6b13d78cd81fd48d172dbd7b3498edb575d0f4afaa67a8aaa044bb3117d943f6ecfff97d3d45df0ff9bdb1899c0b69f93e6e4a81685a4a7ea0" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x4", |
||||
"value": "0x7a120", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690485174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee528307a120801ca016b5a3dfa0d41d6c818ff480dda2c947b97be29c4df29de16331cf42f453b52da05df999089b955280a143ce3f1df6542d83c580418aa66ad0fc23061079c9fbf0" |
||||
"rawTransaction": "0xf8690485174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee528307a1208027a0bf688cfcdc88e07d700ccaab88a1856a33ea74ba10188dbde369cd326b629801a074db255ddf1b9cbf95980ff0433bdbb1f1282cf8a4cb0a02d240fba82992fb0d" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x5", |
||||
"value": "0x927c0", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690585174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830927c0801ba00944e851189f2f9d69ef17bb767b35c10ab2a302c08e0781d9320ebf4c269391a079eb3547e3426bab7077b81b19d4063d10c3f5c5c7d6fb6c137cb5b3742f38ab" |
||||
"rawTransaction": "0xf8690585174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830927c08028a092648d648460e9ebc56597dbe6cdccad3465f0f81aa47d00d1ae1b4319c72977a0565ea274e20717a3b9eafd4e4adfaba25590ced567087d034253a48098ad9590" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x6", |
||||
"value": "0xaae60", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690685174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830aae60801ba00b67a57271f2fbb4290c09a4555053d799c0df0211062e19b6aebaa38c1a9619a00c5204b0c8f5ff5a37bf8fccb6592932c157d8621db35114e621e503de32d47e" |
||||
"rawTransaction": "0xf8690685174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830aae608027a0522cee53d8b50d745c748f8d3be146d2c1c96a9b14f036f1fe6ab5e34a20afe0a00f6a048024bb665440b56414c1c3592c91a01287ef79fbf058d0dc10cc48c673" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x7", |
||||
"value": "0xc3500", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690785174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830c3500801ca0683035ced391473fec92d5eca428c3383f59dcd5a4d3a5c81cab8560ff76d4cda00f01d8078d9f558d872921208d1b3d7698ea88832d6e3a39cd6ccedeb90f738b" |
||||
"rawTransaction": "0xf8690785174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830c35008027a0a45f535b7ca45b8073a9cc5065a2cb58bc5574395a05f10883f71d6184d86d0ca04ef79ebcbef8aa266a51e8ebe2d2c203fd033c8032f2243a0ab6b14f8e45700f" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x8", |
||||
"value": "0xdbba0", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690885174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830dbba0801ca010af0f27c1a5663df2f81ee6b824fc2c040b698d386f2a9ff9a2dddfe8ad564aa04b2464808a1ea6bd4d7d3f37e5a189e0f8d5abc3b9c231da2bc0c31e27149388" |
||||
"rawTransaction": "0xf8690885174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830dbba08027a08e63da2b95526b271536e1e53ccb81b5a580da234d59887cda8f69adc1d97dd7a0660db05c1685ba6978fa14c0da92ce19b89e6f973b0590cfed828082b962cdf3" |
||||
}, |
||||
{ |
||||
"senderAddress": "0x3e881F6C36A3A14a2D1816b0A5471d1caBB16F33", |
||||
"senderAddress": "0x7c41E0668B551f4f902cFaec05B5Bdca68b124CE", |
||||
"receiverAddress": "0x9d72989b68777a1f3FfD6F1DB079f1928373eE52", |
||||
"senderAddressBech32": "one186yp7mpk5ws55tgcz6c223carj4mzmenaal5wz", |
||||
"senderAddressBech32": "one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7", |
||||
"receiverAddressBech32": "one1n4ef3xmgwaap70laduwmq703j2ph8mjjucrkf8", |
||||
"nonce": "0x9", |
||||
"value": "0xf4240", |
||||
"gasLimit": "0x5208", |
||||
"gasPrice": "0x174876e800", |
||||
"rawTransaction": "0xf8690985174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830f4240801ca0ff540fe2800c12ed5bf03a48b33472e4ae0751cb910cb10496545667d70c7a90a0258a23052db64b0c638285405f0781611387791fe083e5df4da5a896a8585d4c" |
||||
"rawTransaction": "0xf8690985174876e8008252088080949d72989b68777a1f3ffd6f1db079f1928373ee52830f42408028a022efd1decb6e80e88fd33f5e189f48105acc72f7e302931221183f86ca8a7015a02001dee44471a5397a4579f733b3a13a86ba1d6c78ad3312187513d6a424f72b" |
||||
} |
||||
] |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,500 @@ |
||||
import { BN } from '@harmony-js/crypto'; |
||||
import * as transformers from '../src/transformers'; |
||||
|
||||
describe('test transformers', () => { |
||||
it('should test unit', () => { |
||||
const { Unit } = transformers; |
||||
const stringConst = '1'; |
||||
const unit1 = new Unit(stringConst); |
||||
const unit2 = new Unit(1); |
||||
const unit3 = new Unit('0x1'); |
||||
|
||||
const unit4 = new Unit('0x'); |
||||
expect(unit4.unit).toEqual('0'); |
||||
|
||||
const fromWei = new Unit(stringConst).asWei(); |
||||
const fromKwei = new Unit(stringConst).asKwei(); |
||||
const fromMwei = new Unit(stringConst).asMwei(); |
||||
const fromGwei = new Unit(stringConst).asGwei(); |
||||
const fromSzabo = new Unit(stringConst).asSzabo(); |
||||
const fromFinney = new Unit(stringConst).asFinney(); |
||||
const fromEther = new Unit(stringConst).asEther(); |
||||
const fromKether = new Unit(stringConst).asKether(); |
||||
const fromMether = new Unit(stringConst).asMether(); |
||||
const fromGether = new Unit(stringConst).asGether(); |
||||
const fromTether = new Unit(stringConst).asTether(); |
||||
|
||||
expect(fromWei.toWei()).toEqual(new BN(stringConst)); |
||||
expect(fromWei.toWeiString()).toEqual(stringConst); |
||||
expect(fromWei.toKwei()).toEqual(`0.00${stringConst}`); |
||||
expect(fromWei.toMwei()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromWei.toGwei()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromWei.toSzabo()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromWei.toFinney()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromWei.toEther()).toEqual(`0.00000000000000000${stringConst}`); |
||||
expect(fromWei.toKether()).toEqual(`0.00000000000000000000${stringConst}`); |
||||
expect(fromWei.toMether()).toEqual(`0.00000000000000000000000${stringConst}`); |
||||
expect(fromWei.toGether()).toEqual(`0.00000000000000000000000000${stringConst}`); |
||||
expect(fromWei.toTether()).toEqual(`0.00000000000000000000000000000${stringConst}`); |
||||
expect(fromWei.toHex()).toEqual(`0x${new BN(stringConst).toString('hex')}`); |
||||
|
||||
expect(fromKwei.toWei()).toEqual(new BN(`${stringConst}000`)); |
||||
expect(fromKwei.toWeiString()).toEqual(`${stringConst}000`); |
||||
expect(fromKwei.toKwei()).toEqual(`${stringConst}`); |
||||
expect(fromKwei.toMwei()).toEqual(`0.00${stringConst}`); |
||||
expect(fromKwei.toGwei()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromKwei.toSzabo()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromKwei.toFinney()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromKwei.toEther()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromKwei.toKether()).toEqual(`0.00000000000000000${stringConst}`); |
||||
expect(fromKwei.toMether()).toEqual(`0.00000000000000000000${stringConst}`); |
||||
expect(fromKwei.toGether()).toEqual(`0.00000000000000000000000${stringConst}`); |
||||
expect(fromKwei.toTether()).toEqual(`0.00000000000000000000000000${stringConst}`); |
||||
expect(fromKwei.toHex()).toEqual(`0x${new BN(`${stringConst}000`).toString('hex')}`); |
||||
|
||||
expect(fromMwei.toWei()).toEqual(new BN(`${stringConst}000000`)); |
||||
expect(fromMwei.toWeiString()).toEqual(`${stringConst}000000`); |
||||
expect(fromMwei.toKwei()).toEqual(`${stringConst}000`); |
||||
expect(fromMwei.toMwei()).toEqual(`${stringConst}`); |
||||
expect(fromMwei.toGwei()).toEqual(`0.00${stringConst}`); |
||||
expect(fromMwei.toSzabo()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromMwei.toFinney()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromMwei.toEther()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromMwei.toKether()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromMwei.toMether()).toEqual(`0.00000000000000000${stringConst}`); |
||||
expect(fromMwei.toGether()).toEqual(`0.00000000000000000000${stringConst}`); |
||||
expect(fromMwei.toTether()).toEqual(`0.00000000000000000000000${stringConst}`); |
||||
expect(fromMwei.toHex()).toEqual(`0x${new BN(`${stringConst}000000`).toString('hex')}`); |
||||
|
||||
expect(fromGwei.toWei()).toEqual(new BN(`${stringConst}000000000`)); |
||||
expect(fromGwei.toWeiString()).toEqual(`${stringConst}000000000`); |
||||
expect(fromGwei.toKwei()).toEqual(`${stringConst}000000`); |
||||
expect(fromGwei.toMwei()).toEqual(`${stringConst}000`); |
||||
expect(fromGwei.toGwei()).toEqual(`${stringConst}`); |
||||
expect(fromGwei.toSzabo()).toEqual(`0.00${stringConst}`); |
||||
expect(fromGwei.toFinney()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromGwei.toEther()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromGwei.toKether()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromGwei.toMether()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromGwei.toGether()).toEqual(`0.00000000000000000${stringConst}`); |
||||
expect(fromGwei.toTether()).toEqual(`0.00000000000000000000${stringConst}`); |
||||
expect(fromGwei.toHex()).toEqual(`0x${new BN(`${stringConst}000000000`).toString('hex')}`); |
||||
|
||||
expect(fromSzabo.toWei()).toEqual(new BN(`${stringConst}000000000000`)); |
||||
expect(fromSzabo.toWeiString()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromSzabo.toKwei()).toEqual(`${stringConst}000000000`); |
||||
expect(fromSzabo.toMwei()).toEqual(`${stringConst}000000`); |
||||
expect(fromSzabo.toGwei()).toEqual(`${stringConst}000`); |
||||
expect(fromSzabo.toSzabo()).toEqual(`${stringConst}`); |
||||
expect(fromSzabo.toFinney()).toEqual(`0.00${stringConst}`); |
||||
expect(fromSzabo.toEther()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromSzabo.toKether()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromSzabo.toMether()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromSzabo.toGether()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromSzabo.toTether()).toEqual(`0.00000000000000000${stringConst}`); |
||||
expect(fromSzabo.toHex()).toEqual(`0x${new BN(`${stringConst}000000000000`).toString('hex')}`); |
||||
|
||||
expect(fromFinney.toWei()).toEqual(new BN(`${stringConst}000000000000000`)); |
||||
expect(fromFinney.toWeiString()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromFinney.toKwei()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromFinney.toMwei()).toEqual(`${stringConst}000000000`); |
||||
expect(fromFinney.toGwei()).toEqual(`${stringConst}000000`); |
||||
expect(fromFinney.toSzabo()).toEqual(`${stringConst}000`); |
||||
expect(fromFinney.toFinney()).toEqual(`${stringConst}`); |
||||
expect(fromFinney.toEther()).toEqual(`0.00${stringConst}`); |
||||
expect(fromFinney.toKether()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromFinney.toMether()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromFinney.toGether()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromFinney.toTether()).toEqual(`0.00000000000000${stringConst}`); |
||||
expect(fromFinney.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(fromEther.toWei()).toEqual(new BN(`${stringConst}000000000000000000`)); |
||||
expect(fromEther.toWeiString()).toEqual(`${stringConst}000000000000000000`); |
||||
expect(fromEther.toKwei()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromEther.toMwei()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromEther.toGwei()).toEqual(`${stringConst}000000000`); |
||||
expect(fromEther.toSzabo()).toEqual(`${stringConst}000000`); |
||||
expect(fromEther.toFinney()).toEqual(`${stringConst}000`); |
||||
expect(fromEther.toEther()).toEqual(`${stringConst}`); |
||||
expect(fromEther.toKether()).toEqual(`0.00${stringConst}`); |
||||
expect(fromEther.toMether()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromEther.toGether()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromEther.toTether()).toEqual(`0.00000000000${stringConst}`); |
||||
expect(fromEther.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(fromKether.toWei()).toEqual(new BN(`${stringConst}000000000000000000000`)); |
||||
expect(fromKether.toWeiString()).toEqual(`${stringConst}000000000000000000000`); |
||||
expect(fromKether.toKwei()).toEqual(`${stringConst}000000000000000000`); |
||||
expect(fromKether.toMwei()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromKether.toGwei()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromKether.toSzabo()).toEqual(`${stringConst}000000000`); |
||||
expect(fromKether.toFinney()).toEqual(`${stringConst}000000`); |
||||
expect(fromKether.toEther()).toEqual(`${stringConst}000`); |
||||
expect(fromKether.toKether()).toEqual(`${stringConst}`); |
||||
expect(fromKether.toMether()).toEqual(`0.00${stringConst}`); |
||||
expect(fromKether.toGether()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromKether.toTether()).toEqual(`0.00000000${stringConst}`); |
||||
expect(fromKether.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(fromMether.toWei()).toEqual(new BN(`${stringConst}000000000000000000000000`)); |
||||
expect(fromMether.toWeiString()).toEqual(`${stringConst}000000000000000000000000`); |
||||
expect(fromMether.toKwei()).toEqual(`${stringConst}000000000000000000000`); |
||||
expect(fromMether.toMwei()).toEqual(`${stringConst}000000000000000000`); |
||||
expect(fromMether.toGwei()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromMether.toSzabo()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromMether.toFinney()).toEqual(`${stringConst}000000000`); |
||||
expect(fromMether.toEther()).toEqual(`${stringConst}000000`); |
||||
expect(fromMether.toKether()).toEqual(`${stringConst}000`); |
||||
expect(fromMether.toMether()).toEqual(`${stringConst}`); |
||||
expect(fromMether.toGether()).toEqual(`0.00${stringConst}`); |
||||
expect(fromMether.toTether()).toEqual(`0.00000${stringConst}`); |
||||
expect(fromMether.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(fromGether.toWei()).toEqual(new BN(`${stringConst}000000000000000000000000000`)); |
||||
expect(fromGether.toWeiString()).toEqual(`${stringConst}000000000000000000000000000`); |
||||
expect(fromGether.toKwei()).toEqual(`${stringConst}000000000000000000000000`); |
||||
expect(fromGether.toMwei()).toEqual(`${stringConst}000000000000000000000`); |
||||
expect(fromGether.toGwei()).toEqual(`${stringConst}000000000000000000`); |
||||
expect(fromGether.toSzabo()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromGether.toFinney()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromGether.toEther()).toEqual(`${stringConst}000000000`); |
||||
expect(fromGether.toKether()).toEqual(`${stringConst}000000`); |
||||
expect(fromGether.toMether()).toEqual(`${stringConst}000`); |
||||
expect(fromGether.toGether()).toEqual(`${stringConst}`); |
||||
expect(fromGether.toTether()).toEqual(`0.00${stringConst}`); |
||||
expect(fromGether.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(fromTether.toWei()).toEqual(new BN(`${stringConst}000000000000000000000000000000`)); |
||||
expect(fromTether.toWeiString()).toEqual(`${stringConst}000000000000000000000000000000`); |
||||
expect(fromTether.toKwei()).toEqual(`${stringConst}000000000000000000000000000`); |
||||
expect(fromTether.toMwei()).toEqual(`${stringConst}000000000000000000000000`); |
||||
expect(fromTether.toGwei()).toEqual(`${stringConst}000000000000000000000`); |
||||
expect(fromTether.toSzabo()).toEqual(`${stringConst}000000000000000000`); |
||||
expect(fromTether.toFinney()).toEqual(`${stringConst}000000000000000`); |
||||
expect(fromTether.toEther()).toEqual(`${stringConst}000000000000`); |
||||
expect(fromTether.toKether()).toEqual(`${stringConst}000000000`); |
||||
expect(fromTether.toMether()).toEqual(`${stringConst}000000`); |
||||
expect(fromTether.toGether()).toEqual(`${stringConst}000`); |
||||
expect(fromTether.toTether()).toEqual(`${stringConst}`); |
||||
expect(fromTether.toHex()).toEqual( |
||||
`0x${new BN(`${stringConst}000000000000000000000000000000`).toString('hex')}`, |
||||
); |
||||
|
||||
expect(unit1.wei).toEqual(unit2.wei); |
||||
expect(unit2.wei).toEqual(unit3.wei); |
||||
|
||||
expect(Unit.Wei(stringConst)).toEqual(fromWei); |
||||
expect(Unit.Kwei(stringConst)).toEqual(fromKwei); |
||||
expect(Unit.Mwei(stringConst)).toEqual(fromMwei); |
||||
expect(Unit.Gwei(stringConst)).toEqual(fromGwei); |
||||
expect(Unit.Szabo(stringConst)).toEqual(fromSzabo); |
||||
expect(Unit.Finney(stringConst)).toEqual(fromFinney); |
||||
expect(Unit.Ether(stringConst)).toEqual(fromEther); |
||||
expect(Unit.Kether(stringConst)).toEqual(fromKether); |
||||
expect(Unit.Mether(stringConst)).toEqual(fromMether); |
||||
expect(Unit.Gether(stringConst)).toEqual(fromGether); |
||||
expect(Unit.Tether(stringConst)).toEqual(fromTether); |
||||
expect(Unit.from(stringConst).wei).toEqual(new Unit(stringConst).wei); |
||||
|
||||
try { |
||||
const ttt = new Unit('').asWei(); |
||||
ttt.wei = <any>undefined; |
||||
ttt.toWei(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttts = new Unit('').asWei(); |
||||
ttts.wei = <any>undefined; |
||||
ttts.toWeiString(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt2 = new Unit('').asWei(); |
||||
ttt2.wei = <any>undefined; |
||||
ttt2.toKwei(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt3 = new Unit('').asWei(); |
||||
ttt3.wei = <any>undefined; |
||||
ttt3.toMwei(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt4 = new Unit('').asWei(); |
||||
ttt4.wei = <any>undefined; |
||||
ttt4.toGwei(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt5 = new Unit('').asWei(); |
||||
ttt5.wei = <any>undefined; |
||||
ttt5.toSzabo(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt6 = new Unit('').asWei(); |
||||
ttt6.wei = <any>undefined; |
||||
ttt6.toFinney(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt7 = new Unit('').asWei(); |
||||
ttt7.wei = <any>undefined; |
||||
ttt7.toEther(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt8 = new Unit('').asWei(); |
||||
ttt8.wei = <any>undefined; |
||||
ttt8.toKether(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt9 = new Unit('').asWei(); |
||||
ttt9.wei = <any>undefined; |
||||
ttt9.toMether(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt10 = new Unit('').asWei(); |
||||
ttt10.wei = <any>undefined; |
||||
ttt10.toGether(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt11 = new Unit('').asWei(); |
||||
ttt11.wei = <any>undefined; |
||||
ttt11.toTether(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
try { |
||||
const ttt12 = new Unit('').asWei(); |
||||
ttt12.wei = <any>undefined; |
||||
ttt12.toHex(); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('error transforming'); |
||||
} |
||||
}); |
||||
it('should test numberToString', () => { |
||||
const { numberToString } = transformers; |
||||
|
||||
const str = '123'; |
||||
const num = 123; |
||||
const bn = new BN(123); |
||||
expect(numberToString(str)).toEqual(str); |
||||
expect(numberToString(num)).toEqual(str); |
||||
expect(numberToString(bn)).toEqual(str); |
||||
try { |
||||
numberToString('abc'); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('cannot parse number:abc to string'); |
||||
} |
||||
}); |
||||
|
||||
it('should test numToStr', () => { |
||||
const num = 123; |
||||
const bigNum = new BN(123); |
||||
const str = '123'; |
||||
|
||||
const wrongStr = 'ijfkl'; |
||||
const wrongSome: any[] = []; |
||||
|
||||
expect(transformers.numToStr(num)).toEqual('123'); |
||||
expect(transformers.numToStr(bigNum)).toEqual('123'); |
||||
expect(transformers.numToStr(str)).toEqual('123'); |
||||
|
||||
try { |
||||
transformers.numToStr(wrongStr); |
||||
} catch (error) { |
||||
expect(error.message).toEqual( |
||||
`while converting number to string, invalid number value '${wrongStr}', should be a number matching (^-?[0-9.]+).`, |
||||
); |
||||
} |
||||
try { |
||||
transformers.numToStr(wrongSome); |
||||
} catch (error) { |
||||
expect(error.message).toEqual( |
||||
`while converting number to string, invalid number value '${wrongSome}' type ${typeof wrongSome}.`, |
||||
); |
||||
} |
||||
}); |
||||
it('should test numToStr', () => { |
||||
const num = 123; |
||||
const bigNum = new BN(123); |
||||
const str = '123'; |
||||
|
||||
const wrongStr = 'ijfkl'; |
||||
const wrongSome: any = []; |
||||
|
||||
expect(transformers.numToStr(num)).toEqual('123'); |
||||
expect(transformers.numToStr(bigNum)).toEqual('123'); |
||||
expect(transformers.numToStr(str)).toEqual('123'); |
||||
|
||||
try { |
||||
transformers.numToStr(wrongStr); |
||||
} catch (error) { |
||||
expect(error.message).toEqual( |
||||
`while converting number to string, invalid number value '${wrongStr}', should be a number matching (^-?[0-9.]+).`, |
||||
); |
||||
} |
||||
try { |
||||
transformers.numToStr(wrongSome); |
||||
} catch (error) { |
||||
expect(error.message).toEqual( |
||||
`while converting number to string, invalid number value '${wrongSome}' type ${typeof wrongSome}.`, |
||||
); |
||||
} |
||||
}); |
||||
it('should test add0xToString', () => { |
||||
expect(transformers.add0xToString('123')).toEqual('0x123'); |
||||
expect(transformers.add0xToString('-123')).toEqual('-0x123'); |
||||
try { |
||||
const obj: any | string = 123; |
||||
transformers.add0xToString(obj); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`123 is not String`); |
||||
} |
||||
}); |
||||
|
||||
it('should test numberToHex', () => { |
||||
expect(transformers.numberToHex('1')).toEqual('0x1'); |
||||
expect(transformers.numberToHex('-1')).toEqual('-0x1'); |
||||
expect(transformers.numberToHex(1)).toEqual('0x1'); |
||||
expect(transformers.numberToHex(-1)).toEqual('-0x1'); |
||||
try { |
||||
const obj: any | string = null; |
||||
transformers.numberToHex(obj); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`cannot parse number:null to string`); |
||||
} |
||||
}); |
||||
it('should test hexToNumber', () => { |
||||
expect(transformers.hexToNumber('0x1')).toEqual('1'); |
||||
expect(transformers.hexToNumber('-0x1')).toEqual('-1'); |
||||
try { |
||||
const obj: any | string = null; |
||||
transformers.hexToNumber(obj); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`null is not string`); |
||||
} |
||||
try { |
||||
const obj2: any | string = '123'; |
||||
transformers.hexToNumber(obj2); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`123 is not hex number`); |
||||
} |
||||
}); |
||||
|
||||
it('should test hexToBN', () => { |
||||
expect(transformers.hexToBN('0x1').toString()).toEqual('1'); |
||||
expect(transformers.hexToBN('-0x1').toString()).toEqual('-1'); |
||||
try { |
||||
const obj: any | string = null; |
||||
transformers.hexToBN(obj); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`null is not string`); |
||||
} |
||||
try { |
||||
const obj2: any | string = '123'; |
||||
transformers.hexToBN(obj2); |
||||
} catch (error) { |
||||
expect(error.message).toEqual(`123 is not hex number`); |
||||
} |
||||
}); |
||||
|
||||
it('should convert Wei to Ether', () => { |
||||
const Wei = new BN('1000000000000000000'); |
||||
const expected = '1'; |
||||
|
||||
expect(transformers.fromWei(Wei, transformers.Units.ether)).toEqual(expected); |
||||
}); |
||||
|
||||
it('should convert Ether to Wei', () => { |
||||
const zil = new BN(1); |
||||
const expected = new BN('1000000000000000000'); |
||||
|
||||
expect(transformers.toWei(zil, transformers.Units.ether).eq(expected)).toBeTruthy(); |
||||
}); |
||||
|
||||
it('fromWei should should work for negative numbers', () => { |
||||
const Wei = new BN('-1000000000000000000'); |
||||
const expected = '-1'; |
||||
|
||||
expect(transformers.fromWei(Wei, transformers.Units.ether)).toEqual(expected); |
||||
}); |
||||
|
||||
it('toWei should should work for negative numbers', () => { |
||||
const zil = new BN(-1); |
||||
const expected = new BN('-1000000000000000000'); |
||||
|
||||
expect(transformers.toWei(zil, transformers.Units.ether)).toEqual(expected); |
||||
}); |
||||
it('fromWei errors', () => { |
||||
try { |
||||
transformers.fromWei('baba', transformers.Units.wei); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('Error: Assertion failed of "[object Object]"'); |
||||
} |
||||
|
||||
try { |
||||
const wrongType: any | transformers.Units = 'ba'; |
||||
transformers.fromWei(new BN(100), wrongType); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('No unit of type ba exists.'); |
||||
} |
||||
expect(transformers.fromWei(new BN(0), transformers.Units.wei, { pad: false })).toEqual('0'); |
||||
}); |
||||
it('toWei errors', () => { |
||||
try { |
||||
transformers.toWei('-1', transformers.Units.wei); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('Cannot convert 1 to wei.'); |
||||
} |
||||
|
||||
try { |
||||
const wrongType: any | transformers.Units = 'ba'; |
||||
transformers.toWei('100000', wrongType); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('No unit of type ba exists.'); |
||||
} |
||||
|
||||
try { |
||||
transformers.toWei('1.00', transformers.Units.wei); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('Cannot convert 1.00 to wei.'); |
||||
} |
||||
try { |
||||
transformers.toWei('100.00.00', transformers.Units.wei); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('Cannot convert 100.00.00 to wei.'); |
||||
} |
||||
try { |
||||
transformers.toWei('.', transformers.Units.wei); |
||||
} catch (error) { |
||||
expect(error.message).toEqual('Cannot convert . to wei.'); |
||||
} |
||||
}); |
||||
}); |
Loading…
Reference in new issue