fix(test):add chainId setting to testSign

staking
neeboo 5 years ago
parent 6e7453f8a7
commit 4b7d95c429
  1. 17
      packages/harmony-contract/src/methods/method.ts
  2. 49
      packages/harmony-transaction/test/testSign.test.ts

@ -131,12 +131,15 @@ export class ContractMethod {
}
}
const result = await (<Wallet>this.wallet).messenger.send(
RPCMethod.Call,
[sendPayload, blockNumber],
(<Wallet>this.wallet).messenger.chainPrefix,
shardID,
);
const result =
// tslint:disable-line
await (<Wallet>this.wallet).messenger.send(
RPCMethod.Call,
[sendPayload, blockNumber],
// tslint:disable-line
(<Wallet>this.wallet).messenger.chainPrefix,
shardID,
);
this.callPayload = sendPayload;
this.callResponse = result;
if (result.isError()) {
@ -155,6 +158,7 @@ export class ContractMethod {
async estimateGas() {
try {
const result = getResultForData(
// tslint:disable-line
await (<Wallet>this.wallet).messenger.send(RPCMethod.EstimateGas, [
{
to: this.transaction.txParams.to,
@ -261,6 +265,7 @@ export class ContractMethod {
data: this.encodeABI(),
};
// tslint:disable-line
const result = new TransactionFactory((<Wallet>this.wallet).messenger).newTx(txObject);
return result;

@ -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());
}
});
});

Loading…
Cancel
Save