2021-02-04 19:15:23 +01:00
|
|
|
import { strict as assert } from 'assert';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionEnvelopeType } from '../../../../../shared/constants/transaction';
|
2021-06-29 21:25:56 +02:00
|
|
|
import { BURN_ADDRESS } from '../../../../../shared/modules/hexstring-utils';
|
2023-01-27 19:28:03 +01:00
|
|
|
import { GasRecommendations } from '../../../../../shared/constants/gas';
|
2021-03-16 22:00:08 +01:00
|
|
|
import * as txUtils from './util';
|
2017-03-07 20:34:11 +01:00
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
describe('txUtils', function () {
|
2018-04-06 20:07:20 +02:00
|
|
|
describe('#validateTxParams', function () {
|
|
|
|
it('does not throw for positive values', function () {
|
2019-12-03 15:52:01 +01:00
|
|
|
const sample = {
|
2018-04-06 20:07:20 +02:00
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
2020-12-04 03:15:59 +01:00
|
|
|
to: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
|
2018-04-06 20:07:20 +02:00
|
|
|
value: '0x01',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
txUtils.validateTxParams(sample);
|
|
|
|
});
|
2017-03-07 20:34:11 +01:00
|
|
|
|
2020-12-04 03:15:59 +01:00
|
|
|
it('throws for invalid params value', function () {
|
|
|
|
assert.throws(() => txUtils.validateTxParams(), {
|
|
|
|
message: 'Invalid transaction params: must be an object.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-04 03:15:59 +01:00
|
|
|
assert.throws(() => txUtils.validateTxParams(null), {
|
|
|
|
message: 'Invalid transaction params: must be an object.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-04 03:15:59 +01:00
|
|
|
assert.throws(() => txUtils.validateTxParams(true), {
|
|
|
|
message: 'Invalid transaction params: must be an object.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-04 03:15:59 +01:00
|
|
|
assert.throws(() => txUtils.validateTxParams([]), {
|
|
|
|
message: 'Invalid transaction params: must be an object.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-12-04 03:15:59 +01:00
|
|
|
|
|
|
|
it('throws for missing "to" and "data"', function () {
|
2019-12-03 15:52:01 +01:00
|
|
|
const sample = {
|
2018-04-06 20:07:20 +02:00
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
2020-12-04 03:15:59 +01:00
|
|
|
value: '0x01',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-04 03:15:59 +01:00
|
|
|
assert.throws(() => txUtils.validateTxParams(sample), {
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: must specify "data" for contract deployments, or "to" (and optionally "data") for all other types of transactions.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-12-04 03:15:59 +01:00
|
|
|
|
|
|
|
it('throws for negative values', function () {
|
|
|
|
const sample = {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
to: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
|
|
|
|
value: '-0x01',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-04 03:15:59 +01:00
|
|
|
assert.throws(() => txUtils.validateTxParams(sample), {
|
|
|
|
message: 'Invalid transaction value "-0x01": not a positive number.',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-06-29 21:25:56 +02:00
|
|
|
|
|
|
|
describe('when validating gasPrice', function () {
|
|
|
|
it('should error when specifying incorrect type', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.feeMarket,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message: `Invalid transaction envelope type: specified type "0x2" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when gasPrice is not a string', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: 1,
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: gasPrice is not a string. got: (1)',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when specifying maxFeePerGas', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
|
|
|
maxFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: specified gasPrice but also included maxFeePerGas, these cannot be mixed',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when specifying maxPriorityFeePerGas', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: specified gasPrice but also included maxPriorityFeePerGas, these cannot be mixed',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if gasPrice is set with no type or EIP-1559 gas fields', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if gasPrice is set with a type of "0x0"', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when validating maxFeePerGas', function () {
|
|
|
|
it('should error when specifying incorrect type', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxFeePerGas: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction envelope type: specified type "0x0" but including maxFeePerGas and maxPriorityFeePerGas requires type: "0x2"',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when maxFeePerGas is not a string', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxFeePerGas: 1,
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: maxFeePerGas is not a string. got: (1)',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when specifying gasPrice', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
|
|
|
maxFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: specified gasPrice but also included maxFeePerGas, these cannot be mixed',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if maxFeePerGas is set with no type or gasPrice field', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if maxFeePerGas is set with a type of "0x2"', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxFeePerGas: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.feeMarket,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when validating maxPriorityFeePerGas', function () {
|
|
|
|
it('should error when specifying incorrect type', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction envelope type: specified type "0x0" but including maxFeePerGas and maxPriorityFeePerGas requires type: "0x2"',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when maxFeePerGas is not a string', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: 1,
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: maxPriorityFeePerGas is not a string. got: (1)',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when specifying gasPrice', function () {
|
|
|
|
const txParams = {
|
|
|
|
gasPrice: '0x1',
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: specified gasPrice but also included maxPriorityFeePerGas, these cannot be mixed',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if maxPriorityFeePerGas is set with no type or gasPrice field', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate if maxPriorityFeePerGas is set with a type of "0x2"', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.feeMarket,
|
2021-06-29 21:25:56 +02:00
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams));
|
|
|
|
});
|
|
|
|
});
|
2021-08-02 17:38:01 +02:00
|
|
|
|
|
|
|
describe('when validating EIP-1559 transactions', function () {
|
|
|
|
it('should error when network does not support EIP-1559', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
maxFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
txUtils.validateTxParams(txParams, false);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
message:
|
|
|
|
'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should validate when network does support EIP-1559', function () {
|
|
|
|
const txParams = {
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
maxFeePerGas: '0x1',
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
};
|
|
|
|
assert.doesNotThrow(() => txUtils.validateTxParams(txParams, true));
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-03-30 23:23:23 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('#normalizeTxParams', function () {
|
|
|
|
it('should normalize txParams', function () {
|
2018-07-03 00:49:33 +02:00
|
|
|
const txParams = {
|
2018-04-06 20:07:20 +02:00
|
|
|
chainId: '0x1',
|
|
|
|
from: 'a7df1beDBF813f57096dF77FCd515f0B3900e402',
|
|
|
|
to: null,
|
|
|
|
data: '68656c6c6f20776f726c64',
|
|
|
|
random: 'hello world',
|
2021-06-29 21:25:56 +02:00
|
|
|
gasPrice: '1',
|
|
|
|
maxFeePerGas: '1',
|
|
|
|
maxPriorityFeePerGas: '1',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimateSuggested: GasRecommendations.medium,
|
|
|
|
estimateUsed: GasRecommendations.high,
|
2021-06-29 21:25:56 +02:00
|
|
|
type: '1',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-06 20:07:20 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let normalizedTxParams = txUtils.normalizeTxParams(txParams);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(!normalizedTxParams.chainId, 'there should be no chainId');
|
|
|
|
assert.ok(
|
|
|
|
!normalizedTxParams.to,
|
|
|
|
'there should be no to address if null',
|
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.from.slice(0, 2),
|
|
|
|
'0x',
|
|
|
|
'from should be hex-prefixed',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.data.slice(0, 2),
|
|
|
|
'0x',
|
|
|
|
'data should be hex-prefixed',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
!('random' in normalizedTxParams),
|
|
|
|
'there should be no random key in normalizedTxParams',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
txParams.to = 'a7df1beDBF813f57096dF77FCd515f0B3900e402';
|
|
|
|
normalizedTxParams = txUtils.normalizeTxParams(txParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.to.slice(0, 2),
|
|
|
|
'0x',
|
|
|
|
'to should be hex-prefixed',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-06-29 21:25:56 +02:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.gasPrice,
|
|
|
|
'0x1',
|
|
|
|
'gasPrice should be hex-prefixed',
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.maxFeePerGas,
|
|
|
|
'0x1',
|
|
|
|
'maxFeePerGas should be hex-prefixed',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.maxPriorityFeePerGas,
|
|
|
|
'0x1',
|
|
|
|
'maxPriorityFeePerGas should be hex-prefixed',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.type,
|
|
|
|
'0x1',
|
|
|
|
'type should be hex-prefixed',
|
|
|
|
);
|
2021-10-22 22:42:20 +02:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.estimateSuggested,
|
2023-01-27 19:28:03 +01:00
|
|
|
GasRecommendations.medium,
|
2021-10-22 22:42:20 +02:00
|
|
|
'estimateSuggested should be the string originally provided',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
normalizedTxParams.estimateUsed,
|
2023-01-27 19:28:03 +01:00
|
|
|
GasRecommendations.high,
|
2021-10-22 22:42:20 +02:00
|
|
|
'estimateSuggested should be the string originally provided',
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 23:35:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('#validateRecipient', function () {
|
2018-04-06 20:07:20 +02:00
|
|
|
it('removes recipient for txParams with 0x when contract data is provided', function () {
|
2020-04-20 17:01:00 +02:00
|
|
|
const zeroRecipientDataTxParams = {
|
2018-04-06 20:07:20 +02:00
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
to: '0x',
|
|
|
|
data: 'bytecode',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-03 00:41:28 +01:00
|
|
|
const sanitizedTxParams = txUtils.validateRecipient(
|
|
|
|
zeroRecipientDataTxParams,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
sanitizedTxParams,
|
|
|
|
{
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
data: 'bytecode',
|
|
|
|
},
|
|
|
|
'no recipient with 0x',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2017-03-08 07:28:02 +01:00
|
|
|
|
2018-04-06 20:07:20 +02:00
|
|
|
it('should error when recipient is 0x', function () {
|
|
|
|
const zeroRecipientTxParams = {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
to: '0x',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txUtils.validateRecipient(zeroRecipientTxParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
'Invalid recipient address',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-04-06 20:07:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('#validateFrom', function () {
|
2018-04-06 20:07:20 +02:00
|
|
|
it('should error when from is not a hex string', function () {
|
|
|
|
// where from is undefined
|
2021-02-04 19:15:23 +01:00
|
|
|
const txParams = {};
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txUtils.validateFrom(txParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
`Invalid from address ${txParams.from} not a string`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
|
|
|
// where from is array
|
2021-02-04 19:15:23 +01:00
|
|
|
txParams.from = [];
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txUtils.validateFrom(txParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
`Invalid from address ${txParams.from} not a string`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
|
|
|
// where from is a object
|
2021-02-04 19:15:23 +01:00
|
|
|
txParams.from = {};
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txUtils.validateFrom(txParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
`Invalid from address ${txParams.from} not a string`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
|
|
|
// where from is a invalid address
|
2021-02-04 19:15:23 +01:00
|
|
|
txParams.from = 'im going to fail';
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txUtils.validateFrom(txParams);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
`Invalid from address`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-06 20:07:20 +02:00
|
|
|
|
|
|
|
// should run
|
2021-02-04 19:15:23 +01:00
|
|
|
txParams.from = '0x1678a085c290ebd122dc42cba69373b5953b831d';
|
|
|
|
txUtils.validateFrom(txParams);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|