test: add integration tests for Account requests (#1643)

This commit is contained in:
Mayukha Vadari
2021-09-24 12:20:04 -04:00
parent b5b2909fed
commit 564001515d
15 changed files with 551 additions and 34 deletions

View File

@@ -23,7 +23,7 @@ export interface AccountChannelsRequest extends BaseRequest {
destination_account?: string
ledger_hash?: string
ledger_index?: LedgerIndex
limit: number
limit?: number
marker?: unknown
}

View File

@@ -6,7 +6,7 @@ export interface GatewayBalancesRequest extends BaseRequest {
command: 'gateway_balances'
account: string
strict?: boolean
hotwallet: string | string[]
hotwallet?: string | string[]
ledger_hash?: string
ledger_index?: LedgerIndex
}

View File

@@ -2,7 +2,7 @@ To run integration tests:
1. Run rippled-standalone node, either in a docker container (preferred) or by installing rippled.
* With docker, run `docker run -p 6006:6006 -it natenichols/rippled-standalone:latest`
* Or [download and build rippled](https://xrpl.org/install-rippled.html) and run `./rippled -a`
2. Run `yarn test:integration` or `yarn test:browser`
2. Run `npm test:integration` or `npm test:browser`
When editing integration tests:
* All imports should be from `xrpl-local` instead of `../../src` (browser tests need this)

17
test/integration/index.ts Normal file
View File

@@ -0,0 +1,17 @@
/* eslint-disable import/export -- Tells webpack which files exist. */
export * from './transactions/signerListSet'
export * from './transactions/payment'
export * from './transactions/offerCreate'
export * from './transactions/offerCancel'
export * from './transactions/signerListSet'
export * from './requests/accountChannels'
export * from './requests/accountCurrencies'
export * from './requests/accountInfo'
export * from './requests/accountLines'
export * from './requests/accountObjects'
export * from './requests/accountOffers'
export * from './requests/accountTx'
export * from './requests/gatewayBalances'
export * from './requests/noRippleCheck'
export * from './requests/utility'
export * from './integration'

View File

@@ -0,0 +1,48 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountChannelsRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_channels', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountChannelsRequest = {
command: 'account_channels',
account: this.wallet.getClassicAddress(),
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account: this.wallet.getClassicAddress(),
channels: [],
ledger_hash:
'C8BFA74A740AA22AD9BD724781589319052398B0C6C817B88D55628E07B7B4A1',
ledger_index: 150,
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_hash', 'ledger_index']),
_.omit(expected.result, ['ledger_hash', 'ledger_index']),
)
})
})

View File

@@ -0,0 +1,49 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountCurrenciesRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_currencies', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountCurrenciesRequest = {
command: 'account_currencies',
account: this.wallet.getClassicAddress(),
strict: true,
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
receive_currencies: [],
send_currencies: [],
ledger_hash:
'C8BFA74A740AA22AD9BD724781589319052398B0C6C817B88D55628E07B7B4A1',
ledger_index: 150,
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_hash', 'ledger_index']),
_.omit(expected.result, ['ledger_hash', 'ledger_index']),
)
})
})

View File

@@ -0,0 +1,78 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountInfoRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_info', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountInfoRequest = {
command: 'account_info',
account: this.wallet.getClassicAddress(),
strict: true,
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account_data: {
Account: this.wallet.getClassicAddress(),
Balance: '400000000',
Flags: 0,
LedgerEntryType: 'AccountRoot',
OwnerCount: 0,
PreviousTxnID:
'19A8211695785A3A02C1C287D93C2B049E83A9CD609825E721052D63FF4F0EC8',
PreviousTxnLgrSeq: 582,
Sequence: 283,
index:
'BD4815E6EB304136E6044F778FB68D4E464CC8DFC59B8F6CC93D90A3709AE194',
},
ledger_hash:
'F0DEEC46A7185BBB535517EE38CF2025973022D5B0532B36407F492521FDB0C6',
ledger_index: 582,
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(response.result.validated, expected.result.validated)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.equal(typeof response.result.account_data.PreviousTxnID, 'string')
assert.equal(typeof response.result.account_data.index, 'string')
assert.equal(
typeof response.result.account_data.PreviousTxnLgrSeq,
'number',
)
assert.equal(typeof response.result.account_data.Sequence, 'number')
assert.deepEqual(
_.omit(response.result.account_data, [
'PreviousTxnID',
'PreviousTxnLgrSeq',
'Sequence',
'index',
]),
_.omit(expected.result.account_data, [
'PreviousTxnID',
'PreviousTxnLgrSeq',
'Sequence',
'index',
]),
)
})
})

View File

@@ -0,0 +1,49 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountLinesRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_lines', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountLinesRequest = {
command: 'account_lines',
account: this.wallet.getClassicAddress(),
strict: true,
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account: this.wallet.getClassicAddress(),
ledger_hash:
'0C09AAFA88AC1A616058220CF33269788D3985DAA6F2386196D4A7404252BB61',
ledger_index: 1074,
lines: [],
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_hash', 'ledger_index']),
_.omit(expected.result, ['ledger_hash', 'ledger_index']),
)
})
})

View File

@@ -0,0 +1,48 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountObjectsRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_objects', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountObjectsRequest = {
command: 'account_objects',
account: this.wallet.getClassicAddress(),
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account: this.wallet.getClassicAddress(),
account_objects: [],
ledger_hash:
'28D68B351ED58B9819502EF5FC05BA4412A048597E5159E1C226703BDF7C7897',
ledger_index: 1294,
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_hash', 'ledger_index']),
_.omit(expected.result, ['ledger_hash', 'ledger_index']),
)
})
})

View File

@@ -0,0 +1,45 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountOffersRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_offers', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountOffersRequest = {
command: 'account_offers',
account: this.wallet.getClassicAddress(),
strict: true,
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account: this.wallet.getClassicAddress(),
ledger_current_index: 1443,
offers: [],
validated: false,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_current_index, 'number')
assert.deepEqual(
_.omit(response.result, 'ledger_current_index'),
_.omit(expected.result, 'ledger_current_index'),
)
})
})

View File

@@ -0,0 +1,103 @@
import { assert } from 'chai'
import _ from 'lodash'
import { AccountTxRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('account_tx', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: AccountTxRequest = {
command: 'account_tx',
account: this.wallet.getClassicAddress(),
ledger_index: 'validated',
}
const response = await this.client.request(request)
const expected = {
result: {
account: this.wallet.getClassicAddress(),
limit: 400,
transactions: [
{
tx: {
Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
Amount: '400000000',
Destination: this.wallet.getClassicAddress(),
Fee: '12',
Flags: 0,
LastLedgerSequence: 1753,
Sequence: 843,
SigningPubKey:
'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020',
TransactionType: 'Payment',
TxnSignature:
'30440220693D244BC13967E3DA67BDC974096784ED03DD4ACE6F36645E5176988452AFCF02200F8AB172432913899F27EC5523829AEDAD00CC2445690400E294EDF652A85945',
date: 685747005,
hash: '2E68BC15813B4A836FAC4D80E42E6FDA6410E99AB973937DEA5E6C2E9A116BAB',
inLedger: 1734,
ledger_index: 1734,
},
},
],
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(response.result.account, expected.result.account)
assert.equal(
response.result.transactions[0].meta.TransactionResult,
'tesSUCCESS',
)
assert.equal(
typeof response.result.transactions[0].tx.LastLedgerSequence,
'number',
)
assert.equal(typeof response.result.transactions[0].tx.Sequence, 'number')
assert.equal(
typeof response.result.transactions[0].tx.SigningPubKey,
'string',
)
assert.equal(
typeof response.result.transactions[0].tx.TxnSignature,
'string',
)
assert.equal(typeof response.result.transactions[0].tx.Fee, 'string')
assert.equal(typeof response.result.transactions[0].tx.hash, 'string')
assert.equal(typeof response.result.transactions[0].tx.inLedger, 'number')
assert.equal(
typeof response.result.transactions[0].tx.ledger_index,
'number',
)
const responseTx = response.result.transactions[0].tx
const expectedTx = expected.result.transactions[0].tx
assert.deepEqual(
[
responseTx.Flags,
responseTx.TransactionType,
responseTx.Account,
responseTx.Amount,
responseTx.Destination,
],
[
expectedTx.Flags,
expectedTx.TransactionType,
expectedTx.Account,
expectedTx.Amount,
expectedTx.Destination,
],
)
})
})

View File

@@ -0,0 +1,48 @@
import { assert } from 'chai'
import _ from 'lodash'
import { GatewayBalancesRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('gateway_balances', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: GatewayBalancesRequest = {
command: 'gateway_balances',
account: this.wallet.getClassicAddress(),
ledger_index: 'validated',
strict: true,
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
account: this.wallet.getClassicAddress(),
ledger_hash:
'28D68B351ED58B9819502EF5FC05BA4412A048597E5159E1C226703BDF7C7897',
ledger_index: 1294,
validated: true,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_hash, 'string')
assert.equal(typeof response.result.ledger_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_hash', 'ledger_index']),
_.omit(expected.result, ['ledger_hash', 'ledger_index']),
)
})
})

View File

@@ -0,0 +1,61 @@
import { assert } from 'chai'
import _ from 'lodash'
import { NoRippleCheckRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('noripple_check', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: NoRippleCheckRequest = {
command: 'noripple_check',
account: this.wallet.getClassicAddress(),
role: 'gateway',
ledger_index: 'current',
transactions: true,
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
ledger_current_index: 2535,
problems: ['You should immediately set your default ripple flag'],
transactions: [
{
Account: this.wallet.getClassicAddress(),
Fee: 10,
Sequence: 1268,
SetFlag: 8,
TransactionType: 'AccountSet',
},
],
validated: false,
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.transactions[0].Fee, 'number')
assert.equal(typeof response.result.transactions[0].Sequence, 'number')
assert.equal(typeof response.result.problems, 'object')
assert.equal(typeof response.result.problems[0], 'string')
const responseTx = response.result.transactions[0]
const expectedTx = expected.result.transactions[0]
assert.deepEqual(
[responseTx.Account, responseTx.SetFlag, responseTx.TransactionType],
[expectedTx.Account, expectedTx.SetFlag, expectedTx.TransactionType],
)
})
})

View File

@@ -17,15 +17,7 @@
mocha.ui('bdd')
</script>
<script src="../testCompiledForWeb/offerCancel.js"></script>
<script src="../testCompiledForWeb/offerCreate.js"></script>
<script src="../testCompiledForWeb/payment.js"></script>
<script src="../testCompiledForWeb/signerListSet.js"></script>
<script src="../testCompiledForWeb/utility.js"></script>
<script src="../testCompiledForWeb/tx.js"></script>
<script src="../testCompiledForWeb/submit.js"></script>
<script src="../testCompiledForWeb/multisign.js"></script>
<script src="../testCompiledForWeb/integration.js"></script>
<script src="../testCompiledForWeb/index.js"></script>
<script>
mocha.run()

View File

@@ -120,30 +120,9 @@ function webpackForTest(testFileName) {
},
},
}
// return Object.assign({}, getDefaultConfiguration(), test)
return test
}
function webpackIntegrationTests() {
const dir = './test/integration/'
const tests = []
const dirPaths = fs.readdirSync(dir)
tests.push(webpackForTest(`./${path.join(dir, 'integration.ts')}`))
const subdirs = dirPaths.filter(
(filename) =>
!filename.match(/\/?([^\/]*)\.ts$/) && filename !== 'README.md',
)
subdirs.forEach((subdir) => {
const subdirPaths = fs.readdirSync(path.join(dir, subdir))
subdirPaths.forEach((filename) => {
tests.push(webpackForTest(`./${path.join(dir, subdir, filename)}`))
})
})
return tests.map(
(test) => (env, argv) => Object.assign({}, getDefaultConfiguration(), test),
)
}
module.exports = [
(env, argv) => {
const config = getDefaultConfiguration()
@@ -160,5 +139,5 @@ module.exports = [
}
return config
},
...webpackIntegrationTests(),
(env, argv) => webpackForTest('./test/integration/index.ts'),
]