-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(abstract-eth): add chain id as network identifier
- Loading branch information
1 parent
2590e01
commit a5a6aac
Showing
28 changed files
with
581 additions
and
276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
"check-fmt": "prettier --check .", | ||
"clean": "rm -r ./dist", | ||
"lint": "eslint --quiet .", | ||
"prepare": "npm run build" | ||
"prepare": "npm run build", | ||
"test": "npm run coverage", | ||
"coverage": "nyc -- npm run unit-test", | ||
"unit-test": "mocha" | ||
}, | ||
"author": "BitGo SDK Team <[email protected]>", | ||
"license": "MIT", | ||
|
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
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
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
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
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
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,80 @@ | ||
import assert from 'assert'; | ||
import should from 'should'; | ||
import { KeyPair, TransferBuilder } from '../../src'; | ||
|
||
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 builder = new TransferBuilder() | ||
.coin(coin) | ||
.expirationTime(1590078260) | ||
.amount(amount) | ||
.to(toAddress) | ||
.contractSequenceId(2) | ||
.key('invalidkey'); | ||
should(() => { | ||
builder.signAndBuild(); | ||
}).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()); | ||
}); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,23 +1 @@ | ||
import { TransferBuilder as EthTransferBuilder } from '@bitgo/abstract-eth'; | ||
|
||
export class TransferBuilder extends EthTransferBuilder { | ||
/** | ||
* Get the prefix used in generating an operation hash for sending native coins | ||
* See https://github.com/BitGo/eth-multisig-v4/blob/master/contracts/coins/ArbethWalletSimple.sol | ||
* | ||
* @returns the string prefix | ||
*/ | ||
protected getNativeOperationHashPrefix(): string { | ||
return 'ARBETH'; | ||
} | ||
|
||
/** | ||
* Get the prefix used in generating an operation hash for sending tokens | ||
* See https://github.com/BitGo/eth-multisig-v4/blob/master/contracts/coins/ArbethWalletSimple.sol | ||
* | ||
* @returns the string prefix | ||
*/ | ||
protected getTokenOperationHashPrefix(): string { | ||
return 'ARBETH-ERC20'; | ||
} | ||
} | ||
export { TransferBuilder } from '@bitgo/abstract-eth'; |
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
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
Oops, something went wrong.