mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
test: add integration tests for OfferCreate, OfferCancel (#1634)
* test OfferCreate * test OfferCancel
This commit is contained in:
65
test/integration/transactions/offerCancel.ts
Normal file
65
test/integration/transactions/offerCancel.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
|
import { OfferCreate, OfferCancel } from 'xrpl-local'
|
||||||
|
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('OfferCancel', function () {
|
||||||
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
|
before(suiteClientSetup)
|
||||||
|
beforeEach(_.partial(setupClient, serverUrl))
|
||||||
|
afterEach(teardownClient)
|
||||||
|
|
||||||
|
it('base', async function () {
|
||||||
|
// set up an offer
|
||||||
|
const setupTx: OfferCreate = {
|
||||||
|
TransactionType: 'OfferCreate',
|
||||||
|
Account: this.wallet.getClassicAddress(),
|
||||||
|
TakerGets: '13100000',
|
||||||
|
TakerPays: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.wallet.getClassicAddress(),
|
||||||
|
value: '10',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, setupTx, this.wallet)
|
||||||
|
|
||||||
|
const accountOffersResponse = await this.client.request({
|
||||||
|
command: 'account_offers',
|
||||||
|
account: this.wallet.getClassicAddress(),
|
||||||
|
})
|
||||||
|
assert.lengthOf(
|
||||||
|
accountOffersResponse.result.offers,
|
||||||
|
1,
|
||||||
|
'Should be exactly one offer on the ledger',
|
||||||
|
)
|
||||||
|
const seq = accountOffersResponse.result.offers[0].seq
|
||||||
|
|
||||||
|
// actually test OfferCancel
|
||||||
|
const tx: OfferCancel = {
|
||||||
|
TransactionType: 'OfferCancel',
|
||||||
|
Account: this.wallet.getClassicAddress(),
|
||||||
|
OfferSequence: seq,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, tx, this.wallet)
|
||||||
|
|
||||||
|
const accountOffersResponse2 = await this.client.request({
|
||||||
|
command: 'account_offers',
|
||||||
|
account: this.wallet.getClassicAddress(),
|
||||||
|
})
|
||||||
|
assert.lengthOf(
|
||||||
|
accountOffersResponse2.result.offers,
|
||||||
|
0,
|
||||||
|
'Should not be any offers on the ledger',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
45
test/integration/transactions/offerCreate.ts
Normal file
45
test/integration/transactions/offerCreate.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { assert } from 'chai'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
|
import { OfferCreate } from 'xrpl-local'
|
||||||
|
|
||||||
|
import serverUrl from '../serverUrl'
|
||||||
|
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
|
||||||
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
|
// how long before each test case times out
|
||||||
|
const TIMEOUT = 20000
|
||||||
|
|
||||||
|
describe('OfferCreate', function () {
|
||||||
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
|
before(suiteClientSetup)
|
||||||
|
beforeEach(_.partial(setupClient, serverUrl))
|
||||||
|
afterEach(teardownClient)
|
||||||
|
|
||||||
|
it('base', async function () {
|
||||||
|
const tx: OfferCreate = {
|
||||||
|
TransactionType: 'OfferCreate',
|
||||||
|
Account: this.wallet.getClassicAddress(),
|
||||||
|
TakerGets: '13100000',
|
||||||
|
TakerPays: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.wallet.getClassicAddress(),
|
||||||
|
value: '10',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, tx, this.wallet)
|
||||||
|
|
||||||
|
// confirm that the offer actually went through
|
||||||
|
const accountOffersResponse = await this.client.request({
|
||||||
|
command: 'account_offers',
|
||||||
|
account: this.wallet.getClassicAddress(),
|
||||||
|
})
|
||||||
|
assert.lengthOf(
|
||||||
|
accountOffersResponse.result.offers,
|
||||||
|
1,
|
||||||
|
'Should be exactly one offer on the ledger',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user