|
|
|
@ -11,7 +11,7 @@ const provider = new HttpProvider('http://localhost:9500'); |
|
|
|
|
|
|
|
|
|
describe('test sign tranction', () => { |
|
|
|
|
it('should test sign transaction with ETH settings', () => { |
|
|
|
|
const ethMessenger = new Messenger(provider, ChainType.Ethereum); |
|
|
|
|
const ethMessenger = new Messenger(provider, ChainType.Ethereum, ChainID.Default); |
|
|
|
|
// tslint:disable-next-line: prefer-for-of
|
|
|
|
|
for (let i = 0; i < txnVectors.length; i += 1) { |
|
|
|
|
const vector = txnVectors[i]; |
|
|
|
@ -23,26 +23,13 @@ describe('test sign tranction', () => { |
|
|
|
|
const transaction: Transaction = new Transaction( |
|
|
|
|
{ |
|
|
|
|
gasLimit: |
|
|
|
|
vector.gasLimit && vector.gasLimit !== '0x' |
|
|
|
|
? hexToBN(vector.gasLimit) |
|
|
|
|
: new BN(0), |
|
|
|
|
vector.gasLimit && vector.gasLimit !== '0x' ? hexToBN(vector.gasLimit) : new BN(0), |
|
|
|
|
gasPrice: |
|
|
|
|
vector.gasPrice && vector.gasPrice !== '0x' |
|
|
|
|
? hexToBN(vector.gasPrice) |
|
|
|
|
: new BN(0), |
|
|
|
|
to: |
|
|
|
|
vector.to && vector.to !== '0x' |
|
|
|
|
? getAddress(vector.to).checksum |
|
|
|
|
: '0x', |
|
|
|
|
value: |
|
|
|
|
vector.value && vector.value !== '0x' |
|
|
|
|
? hexToBN(vector.value) |
|
|
|
|
: new BN(0), |
|
|
|
|
vector.gasPrice && vector.gasPrice !== '0x' ? hexToBN(vector.gasPrice) : new BN(0), |
|
|
|
|
to: vector.to && vector.to !== '0x' ? getAddress(vector.to).checksum : '0x', |
|
|
|
|
value: vector.value && vector.value !== '0x' ? hexToBN(vector.value) : new BN(0), |
|
|
|
|
data: vector.data || '0x', |
|
|
|
|
nonce: |
|
|
|
|
vector.nonce && vector.nonce !== '0x' |
|
|
|
|
? hexToBN(vector.nonce).toNumber() |
|
|
|
|
: 0, |
|
|
|
|
nonce: vector.nonce && vector.nonce !== '0x' ? hexToBN(vector.nonce).toNumber() : 0, |
|
|
|
|
}, |
|
|
|
|
ethMessenger, |
|
|
|
|
TxStatus.INTIALIZED, |
|
|
|
@ -56,20 +43,12 @@ describe('test sign tranction', () => { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should test recover from ETHSignedtransaction', () => { |
|
|
|
|
const ethMessenger = new Messenger( |
|
|
|
|
provider, |
|
|
|
|
ChainType.Ethereum, |
|
|
|
|
ChainID.Default, |
|
|
|
|
); |
|
|
|
|
const ethMessenger = new Messenger(provider, ChainType.Ethereum, ChainID.Default); |
|
|
|
|
// tslint:disable-next-line: prefer-for-of
|
|
|
|
|
for (let i = 0; i < txnVectors.length; i += 1) { |
|
|
|
|
const vector = txnVectors[i]; |
|
|
|
|
|
|
|
|
|
const transaction: Transaction = new Transaction( |
|
|
|
|
{}, |
|
|
|
|
ethMessenger, |
|
|
|
|
TxStatus.INTIALIZED, |
|
|
|
|
); |
|
|
|
|
const transaction: Transaction = new Transaction({}, ethMessenger, TxStatus.INTIALIZED); |
|
|
|
|
|
|
|
|
|
transaction.recover(vector.signedTransaction); |
|
|
|
|
|
|
|
|
@ -84,24 +63,18 @@ describe('test sign tranction', () => { |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (vector.nonce && vector.nonce !== '0x') { |
|
|
|
|
expect(transaction.txParams.nonce).toEqual( |
|
|
|
|
hexToBN(vector.nonce).toNumber(), |
|
|
|
|
); |
|
|
|
|
expect(transaction.txParams.nonce).toEqual(hexToBN(vector.nonce).toNumber()); |
|
|
|
|
} |
|
|
|
|
if (vector.data) { |
|
|
|
|
expect(transaction.txParams.data).toEqual(vector.data); |
|
|
|
|
} |
|
|
|
|
if (vector.value && vector.value !== '0x') { |
|
|
|
|
expect(transaction.txParams.value.toString()).toEqual( |
|
|
|
|
hexToBN(vector.value).toString(), |
|
|
|
|
); |
|
|
|
|
expect(transaction.txParams.value.toString()).toEqual(hexToBN(vector.value).toString()); |
|
|
|
|
} |
|
|
|
|
if (vector.to && vector.to !== '0x') { |
|
|
|
|
expect(transaction.txParams.to).toEqual(getAddress(vector.to).checksum); |
|
|
|
|
} |
|
|
|
|
expect(transaction.txParams.from.toLowerCase()).toEqual( |
|
|
|
|
vector.accountAddress.toLowerCase(), |
|
|
|
|
); |
|
|
|
|
expect(transaction.txParams.from.toLowerCase()).toEqual(vector.accountAddress.toLowerCase()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|