test: integration tests for CheckCreate, CheckCancel, CheckCash (#1664)

* test checkCreate

* test CheckCancel

* test CheckCash

* add browser tests
This commit is contained in:
Mayukha Vadari
2021-09-24 12:29:41 -04:00
parent 564001515d
commit 5d67f14ea3
7 changed files with 204 additions and 7 deletions

View File

@@ -32,7 +32,12 @@ import {
computePaymentChannelHash, computePaymentChannelHash,
} from './hashes' } from './hashes'
import signPaymentChannelClaim from './signPaymentChannelClaim' import signPaymentChannelClaim from './signPaymentChannelClaim'
import { rippleTimeToISOTime, ISOTimeToRippleTime } from './timeConversion' import {
rippleTimeToISOTime,
ISOTimeToRippleTime,
rippleTimeToUnixTime,
unixTimeToRippleTime,
} from './timeConversion'
import verifyPaymentChannelClaim from './verifyPaymentChannelClaim' import verifyPaymentChannelClaim from './verifyPaymentChannelClaim'
import { xrpToDrops, dropsToXrp } from './xrpConversion' import { xrpToDrops, dropsToXrp } from './xrpConversion'
@@ -86,6 +91,8 @@ export {
removeUndefined, removeUndefined,
rippleTimeToISOTime, rippleTimeToISOTime,
ISOTimeToRippleTime, ISOTimeToRippleTime,
rippleTimeToUnixTime,
unixTimeToRippleTime,
isValidSecret, isValidSecret,
computeSignedTransactionHash, computeSignedTransactionHash,
computeBinaryTransactionSigningHash, computeBinaryTransactionSigningHash,

View File

@@ -6,7 +6,7 @@ const RIPPLE_EPOCH_DIFF = 0x386d4380
* @param rpepoch - (seconds since 1/1/2000 GMT). * @param rpepoch - (seconds since 1/1/2000 GMT).
* @returns Milliseconds since unix epoch. * @returns Milliseconds since unix epoch.
*/ */
function rippleToUnixTimestamp(rpepoch: number): number { function rippleTimeToUnixTime(rpepoch: number): number {
return (rpepoch + RIPPLE_EPOCH_DIFF) * 1000 return (rpepoch + RIPPLE_EPOCH_DIFF) * 1000
} }
@@ -16,7 +16,7 @@ function rippleToUnixTimestamp(rpepoch: number): number {
* @param timestamp - (ms since unix epoch). * @param timestamp - (ms since unix epoch).
* @returns Seconds since Ripple Epoch (1/1/2000 GMT). * @returns Seconds since Ripple Epoch (1/1/2000 GMT).
*/ */
function unixToRippleTimestamp(timestamp: number): number { function unixTimeToRippleTime(timestamp: number): number {
return Math.round(timestamp / 1000) - RIPPLE_EPOCH_DIFF return Math.round(timestamp / 1000) - RIPPLE_EPOCH_DIFF
} }
@@ -27,7 +27,7 @@ function unixToRippleTimestamp(timestamp: number): number {
* @returns Iso8601 international standard date format. * @returns Iso8601 international standard date format.
*/ */
function rippleTimeToISOTime(rippleTime: number): string { function rippleTimeToISOTime(rippleTime: number): string {
return new Date(rippleToUnixTimestamp(rippleTime)).toISOString() return new Date(rippleTimeToUnixTime(rippleTime)).toISOString()
} }
/** /**
@@ -37,7 +37,12 @@ function rippleTimeToISOTime(rippleTime: number): string {
* @returns Seconds since ripple epoch (1/1/2000 GMT). * @returns Seconds since ripple epoch (1/1/2000 GMT).
*/ */
function ISOTimeToRippleTime(iso8601: string): number { function ISOTimeToRippleTime(iso8601: string): number {
return unixToRippleTimestamp(Date.parse(iso8601)) return unixTimeToRippleTime(Date.parse(iso8601))
} }
export { rippleTimeToISOTime, ISOTimeToRippleTime } export {
rippleTimeToUnixTime,
unixTimeToRippleTime,
rippleTimeToISOTime,
ISOTimeToRippleTime,
}

View File

@@ -4,6 +4,11 @@ export * from './transactions/payment'
export * from './transactions/offerCreate' export * from './transactions/offerCreate'
export * from './transactions/offerCancel' export * from './transactions/offerCancel'
export * from './transactions/signerListSet' export * from './transactions/signerListSet'
export * from './transactions/checkCancel'
export * from './transactions/checkCash'
export * from './transactions/checkCreate'
export * from './transactions/depositPreauth'
export * from './requests/accountChannels' export * from './requests/accountChannels'
export * from './requests/accountCurrencies' export * from './requests/accountCurrencies'
export * from './requests/accountInfo' export * from './requests/accountInfo'

View File

@@ -0,0 +1,65 @@
import { assert } from 'chai'
import _ from 'lodash'
import { CheckCreate, CheckCancel } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
import { generateFundedWallet, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('CheckCancel', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const wallet2 = await generateFundedWallet(this.client)
const setupTx: CheckCreate = {
TransactionType: 'CheckCreate',
Account: this.wallet.getClassicAddress(),
Destination: wallet2.getClassicAddress(),
SendMax: '50',
}
await testTransaction(this.client, setupTx, this.wallet)
// get check ID
const response1 = await this.client.request({
command: 'account_objects',
account: this.wallet.getClassicAddress(),
type: 'check',
})
assert.lengthOf(
response1.result.account_objects,
1,
'Should be exactly one check on the ledger',
)
const checkId = response1.result.account_objects[0].index
// actual test - cancel the check
const tx: CheckCancel = {
TransactionType: 'CheckCancel',
Account: this.wallet.getClassicAddress(),
CheckID: checkId,
}
await testTransaction(this.client, tx, this.wallet)
// confirm that the check no longer exists
const accountOffersResponse = await this.client.request({
command: 'account_objects',
account: this.wallet.getClassicAddress(),
type: 'check',
})
assert.lengthOf(
accountOffersResponse.result.account_objects,
0,
'Should be no checks on the ledger',
)
})
})

View File

@@ -0,0 +1,68 @@
import { assert } from 'chai'
import _ from 'lodash'
import { CheckCreate, CheckCash } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
import { generateFundedWallet, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('CheckCash', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const wallet2 = await generateFundedWallet(this.client)
const amount = '500'
const setupTx: CheckCreate = {
TransactionType: 'CheckCreate',
Account: this.wallet.getClassicAddress(),
Destination: wallet2.getClassicAddress(),
SendMax: amount,
}
await testTransaction(this.client, setupTx, this.wallet)
// get check ID
const response1 = await this.client.request({
command: 'account_objects',
account: this.wallet.getClassicAddress(),
type: 'check',
})
assert.lengthOf(
response1.result.account_objects,
1,
'Should be exactly one check on the ledger',
)
const checkId = response1.result.account_objects[0].index
// actual test - cash the check
const tx: CheckCash = {
TransactionType: 'CheckCash',
Account: wallet2.getClassicAddress(),
CheckID: checkId,
Amount: amount,
}
await testTransaction(this.client, tx, wallet2)
// confirm that the check no longer exists
const accountOffersResponse = await this.client.request({
command: 'account_objects',
account: this.wallet.getClassicAddress(),
type: 'check',
})
assert.lengthOf(
accountOffersResponse.result.account_objects,
0,
'Should be no checks on the ledger',
)
})
})

View File

@@ -0,0 +1,43 @@
import { assert } from 'chai'
import _ from 'lodash'
import { CheckCreate } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
import { generateFundedWallet, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('CheckCreate', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const wallet2 = await generateFundedWallet(this.client)
const tx: CheckCreate = {
TransactionType: 'CheckCreate',
Account: this.wallet.getClassicAddress(),
Destination: wallet2.getClassicAddress(),
SendMax: '50',
}
await testTransaction(this.client, tx, this.wallet)
// confirm that the check actually went through
const accountOffersResponse = await this.client.request({
command: 'account_objects',
account: this.wallet.getClassicAddress(),
type: 'check',
})
assert.lengthOf(
accountOffersResponse.result.account_objects,
1,
'Should be exactly one check on the ledger',
)
})
})

View File

@@ -84,7 +84,11 @@ export async function testTransaction(
// check that the transaction was successful // check that the transaction was successful
assert.equal(response.status, 'success') assert.equal(response.status, 'success')
assert.equal(response.type, 'response') assert.equal(response.type, 'response')
assert.equal(response.result.engine_result, 'tesSUCCESS') assert.equal(
response.result.engine_result,
'tesSUCCESS',
response.result.engine_result_message,
)
// check that the transaction is on the ledger // check that the transaction is on the ledger
const signedTx = _.omit(response.result.tx_json, 'hash') const signedTx = _.omit(response.result.tx_json, 'hash')