feature/default_network_editable
parent
4f9ea17185
commit
2a81083f14
@ -0,0 +1,55 @@ |
||||
const assert = require('assert') |
||||
const ObservableStore = require('obs-store') |
||||
const PollingBlockTracker = require('eth-block-tracker') |
||||
|
||||
const BalanceController = require('../../../../app/scripts/controllers/balance') |
||||
const AccountTracker = require('../../../../app/scripts/lib/account-tracker') |
||||
const TransactionController = require('../../../../app/scripts/controllers/transactions') |
||||
const { createTestProviderTools } = require('../../../stub/provider') |
||||
const provider = createTestProviderTools({ scaffold: {}}).provider |
||||
|
||||
const TEST_ADDRESS = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' |
||||
|
||||
const accounts = { |
||||
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': { |
||||
balance: '0x5e942b06dc24c4d50', |
||||
address: TEST_ADDRESS, |
||||
}, |
||||
} |
||||
|
||||
describe('Balance Controller', () => { |
||||
|
||||
let balanceController |
||||
|
||||
it('errors when address, accountTracker, txController, or blockTracker', function () { |
||||
try { |
||||
balanceController = new BalanceController() |
||||
} catch (error) { |
||||
assert.equal(error.message, 'Cannot construct a balance checker without address, accountTracker, txController, and blockTracker.') |
||||
} |
||||
}) |
||||
|
||||
beforeEach(() => { |
||||
balanceController = new BalanceController({ |
||||
address: TEST_ADDRESS, |
||||
accountTracker: new AccountTracker({ |
||||
provider, |
||||
blockTracker: new PollingBlockTracker({ provider }), |
||||
}), |
||||
txController: new TransactionController({ |
||||
provider, |
||||
networkStore: new ObservableStore(), |
||||
blockTracker: new PollingBlockTracker({ provider }), |
||||
}), |
||||
blockTracker: new PollingBlockTracker({ provider }), |
||||
}) |
||||
|
||||
balanceController.accountTracker.store.updateState({ accounts }) |
||||
}) |
||||
|
||||
it('updates balance controller ethBalance from account tracker', async function () { |
||||
await balanceController.updateBalance() |
||||
const balanceControllerState = balanceController.store.getState() |
||||
assert.equal(balanceControllerState.ethBalance, '0x5e942b06dc24c4d50') |
||||
}) |
||||
}) |
@ -0,0 +1,116 @@ |
||||
import assert from 'assert' |
||||
import sinon from 'sinon' |
||||
import NetworkController from '../../../app/scripts/controllers/network/index' |
||||
import TypedMessageManager from '../../../app/scripts/lib/typed-message-manager' |
||||
|
||||
describe('Typed Message Manager', () => { |
||||
let typedMessageManager, msgParamsV1, msgParamsV3, typedMsgs, messages, msgId, numberMsgId |
||||
|
||||
const address = '0xc42edfcc21ed14dda456aa0756c153f7985d8813' |
||||
const networkController = new NetworkController() |
||||
sinon.stub(networkController, 'getNetworkState').returns('1') |
||||
|
||||
beforeEach(() => { |
||||
typedMessageManager = new TypedMessageManager({ |
||||
networkController, |
||||
}) |
||||
|
||||
msgParamsV1 = { |
||||
from: address, |
||||
data: [ |
||||
{ type: 'string', name: 'unit test', value: 'hello there' }, |
||||
{ type: 'uint32', name: 'A number, but not really a number', value: '$$$' }, |
||||
], |
||||
} |
||||
|
||||
msgParamsV3 = { |
||||
from: address, |
||||
data: JSON.stringify({ |
||||
'types': { |
||||
'EIP712Domain': [ |
||||
{'name': 'name', 'type': 'string' }, |
||||
{'name': 'version', 'type': 'string' }, |
||||
{'name': 'chainId', ' type': 'uint256' }, |
||||
{'name': 'verifyingContract', ' type': 'address' }, |
||||
], |
||||
'Person': [ |
||||
{'name': 'name', 'type': 'string' }, |
||||
{'name': 'wallet', ' type': 'address' }, |
||||
], |
||||
'Mail': [ |
||||
{'name': 'from', 'type': 'Person' }, |
||||
{'name': 'to', 'type': 'Person' }, |
||||
{'name': 'contents', 'type': 'string' }, |
||||
], |
||||
}, |
||||
'primaryType': 'Mail', |
||||
'domain': { |
||||
'name': 'Ether Mainl', |
||||
'version': '1', |
||||
'chainId': 1, |
||||
'verifyingContract': '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC', |
||||
}, |
||||
'message': { |
||||
'from': { |
||||
'name': 'Cow', |
||||
'wallet': '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826', |
||||
}, |
||||
'to': { |
||||
'name': 'Bob', |
||||
'wallet': '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB', |
||||
}, |
||||
'contents': 'Hello, Bob!', |
||||
}, |
||||
}), |
||||
} |
||||
|
||||
typedMessageManager.addUnapprovedMessage(msgParamsV3, 'V3') |
||||
typedMsgs = typedMessageManager.getUnapprovedMsgs() |
||||
messages = typedMessageManager.messages |
||||
msgId = Object.keys(typedMsgs)[0] |
||||
messages[0].msgParams.metamaskId = parseInt(msgId) |
||||
numberMsgId = parseInt(msgId) |
||||
}) |
||||
|
||||
it('supports version 1 of signedTypedData', () => { |
||||
typedMessageManager.addUnapprovedMessage(msgParamsV1, 'V1') |
||||
assert.equal(messages[messages.length - 1].msgParams.data, msgParamsV1.data) |
||||
}) |
||||
|
||||
it('has params address', function () { |
||||
assert.equal(typedMsgs[msgId].msgParams.from, address) |
||||
}) |
||||
|
||||
it('adds to unapproved messages and sets status to unapproved', function () { |
||||
assert.equal(typedMsgs[msgId].status, 'unapproved') |
||||
}) |
||||
|
||||
it('validates params', function () { |
||||
assert.doesNotThrow(() => { |
||||
typedMessageManager.validateParams(messages[0]) |
||||
}, 'Does not throw with valid parameters') |
||||
}) |
||||
|
||||
it('gets unapproved by id', function () { |
||||
const getMsg = typedMessageManager.getMsg(numberMsgId) |
||||
assert.equal(getMsg.id, numberMsgId) |
||||
}) |
||||
|
||||
it('approves messages', async function () { |
||||
const messageMetaMaskId = messages[0].msgParams |
||||
typedMessageManager.approveMessage(messageMetaMaskId) |
||||
assert.equal(messages[0].status, 'approved') |
||||
}) |
||||
|
||||
it('sets msg status to signed and adds a raw sig to message details', function () { |
||||
typedMessageManager.setMsgStatusSigned(numberMsgId, 'raw sig') |
||||
assert.equal(messages[0].status, 'signed') |
||||
assert.equal(messages[0].rawSig, 'raw sig') |
||||
}) |
||||
|
||||
it('rejects message', function () { |
||||
typedMessageManager.rejectMsg(numberMsgId) |
||||
assert.equal(messages[0].status, 'rejected') |
||||
}) |
||||
|
||||
}) |
Loading…
Reference in new issue