|
|
|
@ -467,6 +467,106 @@ describe('Transaction Controller', function () { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('#createCancelTransaction', function () { |
|
|
|
|
const selectedAddress = '0x1678a085c290ebd122dc42cba69373b5953b831d'; |
|
|
|
|
const recipientAddress = '0xc42edfcc21ed14dda456aa0756c153f7985d8813'; |
|
|
|
|
|
|
|
|
|
let getSelectedAddress, |
|
|
|
|
getPermittedAccounts, |
|
|
|
|
getDefaultGasFees, |
|
|
|
|
getDefaultGasLimit; |
|
|
|
|
beforeEach(function () { |
|
|
|
|
const hash = |
|
|
|
|
'0x2a5523c6fa98b47b7d9b6c8320179785150b42a16bcff36b398c5062b65657e8'; |
|
|
|
|
providerResultStub.eth_sendRawTransaction = hash; |
|
|
|
|
|
|
|
|
|
getSelectedAddress = sinon |
|
|
|
|
.stub(txController, 'getSelectedAddress') |
|
|
|
|
.returns(selectedAddress); |
|
|
|
|
getDefaultGasFees = sinon |
|
|
|
|
.stub(txController, '_getDefaultGasFees') |
|
|
|
|
.returns({}); |
|
|
|
|
getDefaultGasLimit = sinon |
|
|
|
|
.stub(txController, '_getDefaultGasLimit') |
|
|
|
|
.returns({}); |
|
|
|
|
getPermittedAccounts = sinon |
|
|
|
|
.stub(txController, 'getPermittedAccounts') |
|
|
|
|
.returns([selectedAddress]); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(function () { |
|
|
|
|
getSelectedAddress.restore(); |
|
|
|
|
getPermittedAccounts.restore(); |
|
|
|
|
getDefaultGasFees.restore(); |
|
|
|
|
getDefaultGasLimit.restore(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should add an cancel transaction and return a valid txMeta', async function () { |
|
|
|
|
const txMeta = await txController.addUnapprovedTransaction({ |
|
|
|
|
from: selectedAddress, |
|
|
|
|
to: recipientAddress, |
|
|
|
|
}); |
|
|
|
|
await txController.approveTransaction(txMeta.id); |
|
|
|
|
const cancelTxMeta = await txController.createCancelTransaction( |
|
|
|
|
txMeta.id, |
|
|
|
|
{}, |
|
|
|
|
{ actionId: 12345 }, |
|
|
|
|
); |
|
|
|
|
assert.equal(cancelTxMeta.type, TRANSACTION_TYPES.CANCEL); |
|
|
|
|
const memTxMeta = txController.txStateManager.getTransaction( |
|
|
|
|
cancelTxMeta.id, |
|
|
|
|
); |
|
|
|
|
assert.deepEqual(cancelTxMeta, memTxMeta); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should add only 1 cancel transaction when called twice with same actionId', async function () { |
|
|
|
|
const txMeta = await txController.addUnapprovedTransaction({ |
|
|
|
|
from: selectedAddress, |
|
|
|
|
to: recipientAddress, |
|
|
|
|
}); |
|
|
|
|
await txController.approveTransaction(txMeta.id); |
|
|
|
|
await txController.createCancelTransaction( |
|
|
|
|
txMeta.id, |
|
|
|
|
{}, |
|
|
|
|
{ actionId: 12345 }, |
|
|
|
|
); |
|
|
|
|
const transactionCount1 = |
|
|
|
|
txController.txStateManager.getTransactions().length; |
|
|
|
|
await txController.createCancelTransaction( |
|
|
|
|
txMeta.id, |
|
|
|
|
{}, |
|
|
|
|
{ actionId: 12345 }, |
|
|
|
|
); |
|
|
|
|
const transactionCount2 = |
|
|
|
|
txController.txStateManager.getTransactions().length; |
|
|
|
|
assert.equal(transactionCount1, transactionCount2); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should add multiple transactions when called with different actionId', async function () { |
|
|
|
|
const txMeta = await txController.addUnapprovedTransaction({ |
|
|
|
|
from: selectedAddress, |
|
|
|
|
to: recipientAddress, |
|
|
|
|
}); |
|
|
|
|
await txController.approveTransaction(txMeta.id); |
|
|
|
|
await txController.createCancelTransaction( |
|
|
|
|
txMeta.id, |
|
|
|
|
{}, |
|
|
|
|
undefined, |
|
|
|
|
12345, |
|
|
|
|
); |
|
|
|
|
const transactionCount1 = |
|
|
|
|
txController.txStateManager.getTransactions().length; |
|
|
|
|
await txController.createCancelTransaction( |
|
|
|
|
txMeta.id, |
|
|
|
|
{}, |
|
|
|
|
{ actionId: 11111 }, |
|
|
|
|
); |
|
|
|
|
const transactionCount2 = |
|
|
|
|
txController.txStateManager.getTransactions().length; |
|
|
|
|
assert.equal(transactionCount1 + 1, transactionCount2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('#addTxGasDefaults', function () { |
|
|
|
|
it('should add the tx defaults if their are none', async function () { |
|
|
|
|
txController.txStateManager._addTransactionsToState([ |
|
|
|
|