Skip to content

Commit

Permalink
Test for transaction actions
Browse files Browse the repository at this point in the history
  • Loading branch information
elfinka committed Jul 1, 2020
1 parent f22e035 commit fe432bc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/tests/src/actions/actions.js
Expand Up @@ -22,7 +22,7 @@ export function assertPropertiesEqual(state, expectedState) {
}
}

export function setupState() {
export function setupInitialState() {
const cloneDeep = require('lodash/fp/cloneDeep')
const state = cloneDeep(initialState)

Expand All @@ -37,3 +37,8 @@ describe('Test wallet actions', function() {
this.timeout(5000) // this doesn't work in Mocha with arrow functions
require('./wallet-actions')
})
// eslint-disable-next-line prefer-arrow-callback
describe('Test transaction actions', function() {
this.timeout(5000) // this doesn't work in Mocha with arrow functions
require('./transaction-actions')
})
64 changes: 64 additions & 0 deletions app/tests/src/actions/transaction-actions.js
@@ -0,0 +1,64 @@
import {setupInitialState} from './actions'
import {ADALITE_CONFIG} from '../../../frontend/config'
import mockNetwork from '../common/mock'
import {CRYPTO_PROVIDER_TYPES} from '../../../frontend/wallet/constants'
import mnemonicToWalletSecretDef from '../../../frontend/wallet/helpers/mnemonicToWalletSecretDef'
import assert from 'assert'

let state, action

beforeEach(() => {
;[state, action] = setupInitialState()
})

it('Calculate fee - byron', async () => {
ADALITE_CONFIG.ADALITE_CARDANO_VERSION = 'byron'
const mockNet = mockNetwork(ADALITE_CONFIG)
mockNet.mockBulkAddressSummaryEndpoint()
mockNet.mockGetAccountInfo()
mockNet.mockGetStakePools()
mockNet.mockGetConversionRates()
mockNet.mockUtxoEndpoint()
await action.loadWallet(state, {
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
walletSecretDef: await mnemonicToWalletSecretDef(
'blame matrix water coil diet seat nerve street movie turkey jump bundle'
),
})

state.sendAddress.fieldValue =
'DdzFFzCqrhsvrNGcR93DW8cmrPVVbP6vFxcL1i92WzvqcHrp1K1of4DQ8t8cr3oQgsMbbY1eXKWhrcpfnTohNqrr6zPdLeE3AYBtxxZZ'
state.sendAmount.fieldValue = 10
state.sendAmount.coins = 10000000
state.donationAmount.fieldValue = 5
state.donationAmount.coins = 5000000

await action.calculateFee()
assert.equal(state.transactionFee, 179288)
})

it('Calculate fee - shelley', async () => {
ADALITE_CONFIG.ADALITE_CARDANO_VERSION = 'shelley'
const mockNet = mockNetwork(ADALITE_CONFIG)
mockNet.mockBulkAddressSummaryEndpoint()
mockNet.mockGetAccountInfo()
mockNet.mockGetStakePools()
mockNet.mockGetConversionRates()
mockNet.mockUtxoEndpoint()
await action.loadWallet(state, {
cryptoProviderType: CRYPTO_PROVIDER_TYPES.WALLET_SECRET,
walletSecretDef: await mnemonicToWalletSecretDef(
'blame matrix water coil diet seat nerve street movie turkey jump bundle'
),
})

state.sendAddress.fieldValue =
'addr1qjag9rgwe04haycr283datdrjv3mlttalc2waz34xcct0g4uvf6gdg3dpwrsne4uqng3y47ugp2pp5dvuq0jqlperwj83r4pwxvwuxsgds90s0'
state.sendAmount.fieldValue = 10
state.sendAmount.coins = 10000000
state.donationAmount.fieldValue = 5
state.donationAmount.coins = 5000000

await action.calculateFee()
assert.equal(state.transactionFee, 900000)
})
4 changes: 2 additions & 2 deletions app/tests/src/actions/wallet-actions.js
Expand Up @@ -3,12 +3,12 @@ import {ADALITE_CONFIG} from '../../../frontend/config'
import {CRYPTO_PROVIDER_TYPES} from '../../../frontend/wallet/constants'
import mnemonicToWalletSecretDef from '../../../frontend/wallet/helpers/mnemonicToWalletSecretDef'
import assert from 'assert'
import {assertPropertiesEqual, setupState} from './actions'
import {assertPropertiesEqual, setupInitialState} from './actions'

let state, action

beforeEach(() => {
;[state, action] = setupState()
;[state, action] = setupInitialState()
})

const expectedStateChanges = {
Expand Down

0 comments on commit fe432bc

Please sign in to comment.