-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(abstract-eth): adding utils to src
TICKET: COIN-1322
- Loading branch information
1 parent
b297c9a
commit 51621bd
Showing
11 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...les/abstract-eth/test/unit/transaction.ts → ...ct-eth/src/test-utils/unit/transaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ansactionBuilder/addressInitialization.ts → ...ansactionBuilder/addressInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ransactionBuilder/walletInitialization.ts → ...ransactionBuilder/walletInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
modules/abstract-eth/src/test-utils/unit/transferBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import assert from 'assert'; | ||
import should from 'should'; | ||
import { coins, EthereumNetwork as EthLikeNetwork } from '@bitgo/statics'; | ||
import { KeyPair, TransferBuilder } from '../../lib'; | ||
|
||
describe('Eth send multi sig builder', function () { | ||
const toAddress = '0x7325A3F7d4f9E86AE62Cf742426078C3755730d5'; | ||
const xprv = | ||
'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2'; | ||
const key = new KeyPair({ prv: xprv }).getKeys().prv as string; | ||
const amount = '100000000000000000'; // equivalent to 0.1 ether | ||
const ethLikeCoins = ['hteth', 'tarbeth', 'topeth', 'zketh']; | ||
|
||
describe('should fail', () => { | ||
it('should fail if a coin does not exists in @bitgo/statics', () => { | ||
should(() => { | ||
new TransferBuilder().coin('inexistentcoin'); | ||
}).throw(); | ||
}); | ||
|
||
ethLikeCoins.forEach((coin) => { | ||
it('should fail with an invalid key', () => { | ||
const staticsCoin = coins.get(coin) as unknown as EthLikeNetwork; | ||
const builder = new TransferBuilder() | ||
.coin(coin) | ||
.expirationTime(1590078260) | ||
.amount(amount) | ||
.to(toAddress) | ||
.contractSequenceId(2) | ||
.key('invalidkey'); | ||
should(() => { | ||
builder.signAndBuild(`${staticsCoin.chainId}`); | ||
}).throw('private key length is invalid'); | ||
}); | ||
}); | ||
|
||
it('should fail with an invalid sequence id', () => { | ||
should(() => { | ||
new TransferBuilder().contractSequenceId(-1); | ||
}).throw('Invalid contract sequence id'); | ||
}); | ||
|
||
it('should fail with an invalid destination address', () => { | ||
should(() => { | ||
new TransferBuilder().to('invalidaddress'); | ||
}).throw('Invalid address'); | ||
}); | ||
|
||
it('should fail with an invalid amount: text value', () => { | ||
should(() => { | ||
new TransferBuilder().amount('invalidamount'); | ||
}).throw('Invalid amount'); | ||
}); | ||
|
||
it('should fail with an invalid amount: negative value', () => { | ||
should(() => { | ||
new TransferBuilder().amount('-10'); | ||
}).throw('Invalid amount'); | ||
}); | ||
|
||
it('should fail with an invalid expiration time', () => { | ||
should(() => { | ||
new TransferBuilder().expirationTime(-1); | ||
}).throw('Invalid expiration time'); | ||
}); | ||
|
||
it('should fail if a sequenceId param is missing', () => { | ||
const builder = new TransferBuilder().amount(amount).to(toAddress).key(key); | ||
assert.throws(() => builder.signAndBuild('')); | ||
}); | ||
|
||
it('should fail if a destination param is missing', () => { | ||
const builder = new TransferBuilder().amount(amount).contractSequenceId(2).key(key); | ||
assert.throws(() => builder.signAndBuild('')); | ||
}); | ||
|
||
it('should fail if a amount param is missing', () => { | ||
const builder = new TransferBuilder().to(toAddress).contractSequenceId(2).key(key); | ||
assert.throws(() => builder.signAndBuild('')); | ||
}); | ||
}); | ||
}); |