mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Compare commits
3 Commits
ripple-bin
...
iouescrow-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edfdd42584 | ||
|
|
157a9d9409 | ||
|
|
6c6dade636 |
4
.github/workflows/nodejs.yml
vendored
4
.github/workflows/nodejs.yml
vendored
@@ -102,7 +102,7 @@ jobs:
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
rippled:
|
rippled:
|
||||||
image: natenichols/rippled-standalone:latest
|
image: gcr.io/metaxrplorer/dangell7-iouescrow-standalone:1
|
||||||
ports:
|
ports:
|
||||||
- 6006:6006
|
- 6006:6006
|
||||||
options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s
|
options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s
|
||||||
@@ -153,7 +153,7 @@ jobs:
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
rippled:
|
rippled:
|
||||||
image: natenichols/rippled-standalone:latest
|
image: gcr.io/metaxrplorer/dangell7-iouescrow-standalone:1
|
||||||
ports:
|
ports:
|
||||||
- 6006:6006
|
- 6006:6006
|
||||||
options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s
|
options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ describe('server_state', function () {
|
|||||||
id: 0,
|
id: 0,
|
||||||
result: {
|
result: {
|
||||||
state: {
|
state: {
|
||||||
build_version: '1.7.3',
|
build_version: '1.10.0-rc1',
|
||||||
complete_ledgers: '2563-2932',
|
complete_ledgers: '2563-2932',
|
||||||
io_latency_ms: 1,
|
io_latency_ms: 1,
|
||||||
jq_trans_overflow: '0',
|
jq_trans_overflow: '0',
|
||||||
@@ -103,6 +103,8 @@ describe('server_state', function () {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const removeKeys = [
|
const removeKeys = [
|
||||||
|
'initial_sync_duration_us',
|
||||||
|
'node_size',
|
||||||
'complete_ledgers',
|
'complete_ledgers',
|
||||||
'load',
|
'load',
|
||||||
'state_accounting',
|
'state_accounting',
|
||||||
@@ -133,7 +135,7 @@ describe('server_state', function () {
|
|||||||
)
|
)
|
||||||
assert.equal(
|
assert.equal(
|
||||||
typeof response.result.state.state_accounting[key].transitions,
|
typeof response.result.state.state_accounting[key].transitions,
|
||||||
'number',
|
'string',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ describe('subscribe', function () {
|
|||||||
// Explicitly checking that there are only known fields in the return
|
// Explicitly checking that there are only known fields in the return
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
fee_base: ledgerResponse.fee_base,
|
fee_base: ledgerResponse.fee_base,
|
||||||
fee_ref: ledgerResponse.fee_ref,
|
fee_ref: 0,
|
||||||
ledger_hash: ledgerResponse.ledger_hash,
|
ledger_hash: ledgerResponse.ledger_hash,
|
||||||
ledger_index: ledgerResponse.ledger_index,
|
ledger_index: ledgerResponse.ledger_index,
|
||||||
ledger_time: ledgerResponse.ledger_time,
|
ledger_time: ledgerResponse.ledger_time,
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { Client, Wallet } from '../../src'
|
import { Client, Wallet } from '../../src'
|
||||||
|
import { AccountSet, TrustSet, Payment } from '../../src/models/transactions'
|
||||||
|
|
||||||
import serverUrl from './serverUrl'
|
import serverUrl from './serverUrl'
|
||||||
import { fundAccount } from './utils'
|
import { fundAccount, ledgerAccept } from './utils'
|
||||||
|
|
||||||
export interface XrplIntegrationTestContext {
|
export interface XrplIntegrationTestContext {
|
||||||
client: Client
|
client: Client
|
||||||
wallet: Wallet
|
wallet: Wallet
|
||||||
|
destination: Wallet
|
||||||
|
gateway: Wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function teardownClient(
|
export async function teardownClient(
|
||||||
@@ -29,18 +32,137 @@ async function connectWithRetry(client: Client, tries = 0): Promise<void> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-params -- need comments
|
||||||
|
async function initToken(
|
||||||
|
client: Client,
|
||||||
|
wallet: Wallet,
|
||||||
|
destination: Wallet,
|
||||||
|
gateway: Wallet,
|
||||||
|
): Promise<void> {
|
||||||
|
const atx: AccountSet = {
|
||||||
|
TransactionType: 'AccountSet',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
SetFlag: 8,
|
||||||
|
}
|
||||||
|
const atxr = await client.submit(atx, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (atxr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(atxr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const wtl: TrustSet = {
|
||||||
|
TransactionType: 'TrustSet',
|
||||||
|
Account: wallet.classicAddress,
|
||||||
|
LimitAmount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '100000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const wtlr = await client.submit(wtl, {
|
||||||
|
wallet,
|
||||||
|
})
|
||||||
|
if (wtlr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(wtlr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const dtl: TrustSet = {
|
||||||
|
TransactionType: 'TrustSet',
|
||||||
|
Account: destination.classicAddress,
|
||||||
|
LimitAmount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '100000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dtlr = await client.submit(dtl, {
|
||||||
|
wallet: destination,
|
||||||
|
})
|
||||||
|
if (wtlr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(dtlr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const wp: Payment = {
|
||||||
|
TransactionType: 'Payment',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
Destination: wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '10000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const wpr = await client.submit(wp, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (wpr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(wpr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const dp: Payment = {
|
||||||
|
TransactionType: 'Payment',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
Destination: destination.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '10000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dpr = await client.submit(dp, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (dpr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(dpr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
}
|
||||||
|
|
||||||
export async function setupClient(
|
export async function setupClient(
|
||||||
server = serverUrl,
|
server = serverUrl,
|
||||||
|
token?: boolean | false,
|
||||||
): Promise<XrplIntegrationTestContext> {
|
): Promise<XrplIntegrationTestContext> {
|
||||||
const context: XrplIntegrationTestContext = {
|
const context: XrplIntegrationTestContext = {
|
||||||
client: new Client(server, { timeout: 200000 }),
|
client: new Client(server, { timeout: 200000 }),
|
||||||
wallet: Wallet.generate(),
|
wallet: Wallet.generate(),
|
||||||
|
destination: Wallet.generate(),
|
||||||
|
gateway: Wallet.generate(),
|
||||||
}
|
}
|
||||||
return connectWithRetry(context.client).then(async () => {
|
return connectWithRetry(context.client).then(async () => {
|
||||||
await fundAccount(context.client, context.wallet, {
|
await fundAccount(context.client, context.wallet, {
|
||||||
count: 20,
|
count: 20,
|
||||||
delayMs: 1000,
|
delayMs: 1000,
|
||||||
})
|
})
|
||||||
|
if (token) {
|
||||||
|
await fundAccount(context.client, context.destination, {
|
||||||
|
count: 20,
|
||||||
|
delayMs: 1000,
|
||||||
|
})
|
||||||
|
await fundAccount(context.client, context.gateway, {
|
||||||
|
count: 20,
|
||||||
|
delayMs: 1000,
|
||||||
|
})
|
||||||
|
await initToken(
|
||||||
|
context.client,
|
||||||
|
context.wallet,
|
||||||
|
context.destination,
|
||||||
|
context.gateway,
|
||||||
|
)
|
||||||
|
}
|
||||||
return context
|
return context
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,7 @@ import {
|
|||||||
teardownClient,
|
teardownClient,
|
||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import {
|
import { testTransaction, submitTransaction } from '../utils'
|
||||||
// calculateWaitTimeForTransaction,
|
|
||||||
generateFundedWallet,
|
|
||||||
// getXRPBalance,
|
|
||||||
testTransaction,
|
|
||||||
submitTransaction,
|
|
||||||
} from '../utils'
|
|
||||||
|
|
||||||
// TODO: Fix these tests
|
// TODO: Fix these tests
|
||||||
// NOTE: Because ledger accept is called among multiple tests, the actual ledger close time is not
|
// NOTE: Because ledger accept is called among multiple tests, the actual ledger close time is not
|
||||||
@@ -30,16 +24,13 @@ describe('EscrowCancel', function () {
|
|||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
// Funding the wallet can take some time, so we do it first BEFORE getting the ledger close_time.
|
|
||||||
const wallet1 = await generateFundedWallet(testContext.client)
|
|
||||||
|
|
||||||
// get the most recent close_time from the standalone container for cancel & finish after.
|
// get the most recent close_time from the standalone container for cancel & finish after.
|
||||||
const CLOSE_TIME: number = (
|
const CLOSE_TIME: number = (
|
||||||
await testContext.client.request({
|
await testContext.client.request({
|
||||||
@@ -54,7 +45,7 @@ describe('EscrowCancel', function () {
|
|||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
TransactionType: 'EscrowCreate',
|
TransactionType: 'EscrowCreate',
|
||||||
Amount: '10000',
|
Amount: '10000',
|
||||||
Destination: wallet1.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
CancelAfter: CLOSE_TIME + 3,
|
CancelAfter: CLOSE_TIME + 3,
|
||||||
FinishAfter: CLOSE_TIME + 2,
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
}
|
}
|
||||||
@@ -74,12 +65,101 @@ describe('EscrowCancel', function () {
|
|||||||
})
|
})
|
||||||
).result.account_objects
|
).result.account_objects
|
||||||
|
|
||||||
assert.equal(accountObjects.length, 1)
|
assert.equal(accountObjects.length, 2)
|
||||||
|
|
||||||
const sequence = (
|
const sequence = (
|
||||||
await testContext.client.request({
|
await testContext.client.request({
|
||||||
command: 'tx',
|
command: 'tx',
|
||||||
transaction: accountObjects[0].PreviousTxnID,
|
transaction: accountObjects[1].PreviousTxnID,
|
||||||
|
})
|
||||||
|
).result.Sequence
|
||||||
|
|
||||||
|
if (!sequence) {
|
||||||
|
throw new Error('sequence did not exist')
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelTx: EscrowCancel = {
|
||||||
|
TransactionType: 'EscrowCancel',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
Owner: testContext.wallet.classicAddress,
|
||||||
|
OfferSequence: sequence,
|
||||||
|
}
|
||||||
|
|
||||||
|
// We set the CancelAfter timer to be 3 seconds after the last ledger close_time. We need to wait this long
|
||||||
|
// before we can cancel the escrow.
|
||||||
|
// const cancelAfterTimerPromise = new Promise((resolve) => {
|
||||||
|
// setTimeout(resolve, waitTimeInMs)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// Make sure we wait long enough before canceling the escrow.
|
||||||
|
// await cancelAfterTimerPromise
|
||||||
|
|
||||||
|
// await testTransaction(testContext.client, cancelTx, testContext.wallet, {
|
||||||
|
// count: 20,
|
||||||
|
// delayMs: 2000,
|
||||||
|
// })
|
||||||
|
|
||||||
|
await submitTransaction({
|
||||||
|
client: testContext.client,
|
||||||
|
transaction: cancelTx,
|
||||||
|
wallet: testContext.wallet,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Make sure the Destination wallet did not receive any XRP.
|
||||||
|
// assert.equal(
|
||||||
|
// await getXRPBalance(testContext.client, wallet1),
|
||||||
|
// initialBalanceWallet1,
|
||||||
|
// )
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
// get the most recent close_time from the standalone container for cancel & finish after.
|
||||||
|
const CLOSE_TIME: number = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'ledger',
|
||||||
|
ledger_index: 'validated',
|
||||||
|
})
|
||||||
|
).result.ledger.close_time
|
||||||
|
|
||||||
|
// const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
||||||
|
|
||||||
|
const createTx: EscrowCreate = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'EscrowCreate',
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
|
CancelAfter: CLOSE_TIME + 3,
|
||||||
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, createTx, testContext.wallet)
|
||||||
|
|
||||||
|
// const initialBalanceWallet1 = await getXRPBalance(
|
||||||
|
// testContext.client,
|
||||||
|
// wallet1,
|
||||||
|
// )
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const accountObjects = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects
|
||||||
|
|
||||||
|
assert.equal(accountObjects.length, 2)
|
||||||
|
|
||||||
|
const sequence = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'tx',
|
||||||
|
transaction: accountObjects[1].PreviousTxnID,
|
||||||
})
|
})
|
||||||
).result.Sequence
|
).result.Sequence
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
teardownClient,
|
teardownClient,
|
||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import { generateFundedWallet, testTransaction } from '../utils'
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 20000
|
const TIMEOUT = 20000
|
||||||
@@ -16,15 +16,13 @@ describe('EscrowCreate', function () {
|
|||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
|
||||||
|
|
||||||
// get the most recent close_time from the standalone container for finish after.
|
// get the most recent close_time from the standalone container for finish after.
|
||||||
const CLOSE_TIME: number = (
|
const CLOSE_TIME: number = (
|
||||||
await testContext.client.request({
|
await testContext.client.request({
|
||||||
@@ -37,7 +35,7 @@ describe('EscrowCreate', function () {
|
|||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
TransactionType: 'EscrowCreate',
|
TransactionType: 'EscrowCreate',
|
||||||
Amount: '10000',
|
Amount: '10000',
|
||||||
Destination: wallet2.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
FinishAfter: CLOSE_TIME + 2,
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +49,46 @@ describe('EscrowCreate', function () {
|
|||||||
account: testContext.wallet.classicAddress,
|
account: testContext.wallet.classicAddress,
|
||||||
})
|
})
|
||||||
).result.account_objects.length,
|
).result.account_objects.length,
|
||||||
1,
|
2,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
// get the most recent close_time from the standalone container for finish after.
|
||||||
|
const CLOSE_TIME: number = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'ledger',
|
||||||
|
ledger_index: 'validated',
|
||||||
|
})
|
||||||
|
).result.ledger.close_time
|
||||||
|
|
||||||
|
const tx: EscrowCreate = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'EscrowCreate',
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
2,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TIMEOUT,
|
TIMEOUT,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
} from '../setup'
|
} from '../setup'
|
||||||
import {
|
import {
|
||||||
calculateWaitTimeForTransaction,
|
calculateWaitTimeForTransaction,
|
||||||
generateFundedWallet,
|
|
||||||
getXRPBalance,
|
getXRPBalance,
|
||||||
testTransaction,
|
testTransaction,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
@@ -21,15 +20,13 @@ describe('EscrowFinish', function () {
|
|||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet1 = await generateFundedWallet(testContext.client)
|
|
||||||
|
|
||||||
// get the most recent close_time from the standalone container for cancel & finish after.
|
// get the most recent close_time from the standalone container for cancel & finish after.
|
||||||
const CLOSE_TIME: number = (
|
const CLOSE_TIME: number = (
|
||||||
await testContext.client.request({
|
await testContext.client.request({
|
||||||
@@ -40,13 +37,11 @@ describe('EscrowFinish', function () {
|
|||||||
|
|
||||||
const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
||||||
|
|
||||||
const AMOUNT = 10000
|
|
||||||
|
|
||||||
const createTx: EscrowCreate = {
|
const createTx: EscrowCreate = {
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
TransactionType: 'EscrowCreate',
|
TransactionType: 'EscrowCreate',
|
||||||
Amount: AMOUNT.toString(),
|
Amount: '10000',
|
||||||
Destination: wallet1.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
FinishAfter: CLOSE_TIME + 2,
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +51,10 @@ describe('EscrowFinish', function () {
|
|||||||
|
|
||||||
await testTransaction(testContext.client, createTx, testContext.wallet)
|
await testTransaction(testContext.client, createTx, testContext.wallet)
|
||||||
|
|
||||||
const initialBalance = await getXRPBalance(testContext.client, wallet1)
|
const initialBalance = await getXRPBalance(
|
||||||
|
testContext.client,
|
||||||
|
testContext.destination,
|
||||||
|
)
|
||||||
|
|
||||||
// check that the object was actually created
|
// check that the object was actually created
|
||||||
const accountObjects = (
|
const accountObjects = (
|
||||||
@@ -66,12 +64,12 @@ describe('EscrowFinish', function () {
|
|||||||
})
|
})
|
||||||
).result.account_objects
|
).result.account_objects
|
||||||
|
|
||||||
assert.equal(accountObjects.length, 1)
|
assert.equal(accountObjects.length, 2)
|
||||||
|
|
||||||
const sequence = (
|
const sequence = (
|
||||||
await testContext.client.request({
|
await testContext.client.request({
|
||||||
command: 'tx',
|
command: 'tx',
|
||||||
transaction: accountObjects[0].PreviousTxnID,
|
transaction: accountObjects[1].PreviousTxnID,
|
||||||
})
|
})
|
||||||
).result.Sequence
|
).result.Sequence
|
||||||
|
|
||||||
@@ -86,9 +84,81 @@ describe('EscrowFinish', function () {
|
|||||||
|
|
||||||
await testTransaction(testContext.client, finishTx, testContext.wallet)
|
await testTransaction(testContext.client, finishTx, testContext.wallet)
|
||||||
|
|
||||||
const expectedBalance = String(Number(initialBalance) + Number(AMOUNT))
|
const expectedBalance = String(Number(initialBalance) + Number('10000'))
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await getXRPBalance(testContext.client, wallet1),
|
await getXRPBalance(testContext.client, testContext.destination),
|
||||||
|
expectedBalance,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
// get the most recent close_time from the standalone container for cancel & finish after.
|
||||||
|
const CLOSE_TIME: number = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'ledger',
|
||||||
|
ledger_index: 'validated',
|
||||||
|
})
|
||||||
|
).result.ledger.close_time
|
||||||
|
|
||||||
|
const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
||||||
|
|
||||||
|
const createTx: EscrowCreate = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'EscrowCreate',
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
const finishAfterPromise = new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, waitTimeInMs)
|
||||||
|
})
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, createTx, testContext.wallet)
|
||||||
|
|
||||||
|
const initialBalance = await getXRPBalance(
|
||||||
|
testContext.client,
|
||||||
|
testContext.destination,
|
||||||
|
)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
const accountObjects = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: testContext.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects
|
||||||
|
|
||||||
|
assert.equal(accountObjects.length, 2)
|
||||||
|
|
||||||
|
const sequence = (
|
||||||
|
await testContext.client.request({
|
||||||
|
command: 'tx',
|
||||||
|
transaction: accountObjects[1].PreviousTxnID,
|
||||||
|
})
|
||||||
|
).result.Sequence
|
||||||
|
|
||||||
|
const finishTx: EscrowFinish = {
|
||||||
|
TransactionType: 'EscrowFinish',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
Owner: testContext.wallet.classicAddress,
|
||||||
|
OfferSequence: sequence!,
|
||||||
|
}
|
||||||
|
|
||||||
|
await finishAfterPromise
|
||||||
|
|
||||||
|
await testTransaction(testContext.client, finishTx, testContext.wallet)
|
||||||
|
|
||||||
|
const expectedBalance = String(Number(initialBalance))
|
||||||
|
assert.equal(
|
||||||
|
await getXRPBalance(testContext.client, testContext.destination),
|
||||||
expectedBalance,
|
expectedBalance,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
teardownClient,
|
teardownClient,
|
||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import { generateFundedWallet, testTransaction } from '../utils'
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 20000
|
const TIMEOUT = 20000
|
||||||
@@ -15,19 +15,18 @@ describe('PaymentChannelClaim', function () {
|
|||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
Amount: '100',
|
Amount: '100',
|
||||||
Destination: wallet2.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
SettleDelay: 86400,
|
SettleDelay: 86400,
|
||||||
PublicKey: testContext.wallet.publicKey,
|
PublicKey: testContext.wallet.publicKey,
|
||||||
}
|
}
|
||||||
@@ -48,7 +47,7 @@ describe('PaymentChannelClaim', function () {
|
|||||||
TransactionType: 'PaymentChannelClaim',
|
TransactionType: 'PaymentChannelClaim',
|
||||||
Channel: hashPaymentChannel(
|
Channel: hashPaymentChannel(
|
||||||
testContext.wallet.classicAddress,
|
testContext.wallet.classicAddress,
|
||||||
wallet2.classicAddress,
|
testContext.destination.classicAddress,
|
||||||
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
),
|
),
|
||||||
Amount: '100',
|
Amount: '100',
|
||||||
@@ -62,4 +61,48 @@ describe('PaymentChannelClaim', function () {
|
|||||||
},
|
},
|
||||||
TIMEOUT,
|
TIMEOUT,
|
||||||
)
|
)
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: testContext.wallet.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
const paymentChannelResponse = await testContext.client.submit(
|
||||||
|
paymentChannelCreate,
|
||||||
|
{ wallet: testContext.wallet },
|
||||||
|
)
|
||||||
|
|
||||||
|
const paymentChannelClaim: PaymentChannelClaim = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'PaymentChannelClaim',
|
||||||
|
Channel: hashPaymentChannel(
|
||||||
|
testContext.wallet.classicAddress,
|
||||||
|
testContext.destination.classicAddress,
|
||||||
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
|
),
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(
|
||||||
|
testContext.client,
|
||||||
|
paymentChannelClaim,
|
||||||
|
testContext.wallet,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,32 +1,78 @@
|
|||||||
import { PaymentChannelCreate } from '../../../src'
|
import { PaymentChannelCreate, hashes, PaymentChannelClaim } from '../../../src'
|
||||||
import serverUrl from '../serverUrl'
|
import serverUrl from '../serverUrl'
|
||||||
import {
|
import {
|
||||||
setupClient,
|
setupClient,
|
||||||
teardownClient,
|
teardownClient,
|
||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import { generateFundedWallet, testTransaction } from '../utils'
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 20000
|
const TIMEOUT = 20000
|
||||||
|
const { hashPaymentChannel } = hashes
|
||||||
|
|
||||||
describe('PaymentChannelCreate', function () {
|
describe('PaymentChannelClaim', function () {
|
||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
Amount: '100',
|
Amount: '100',
|
||||||
Destination: wallet2.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: testContext.wallet.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
const paymentChannelResponse = await testContext.client.submit(
|
||||||
|
paymentChannelCreate,
|
||||||
|
{ wallet: testContext.wallet },
|
||||||
|
)
|
||||||
|
|
||||||
|
await testTransaction(
|
||||||
|
testContext.client,
|
||||||
|
paymentChannelCreate,
|
||||||
|
testContext.wallet,
|
||||||
|
)
|
||||||
|
|
||||||
|
const paymentChannelClaim: PaymentChannelClaim = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'PaymentChannelClaim',
|
||||||
|
Channel: hashPaymentChannel(
|
||||||
|
testContext.wallet.classicAddress,
|
||||||
|
testContext.destination.classicAddress,
|
||||||
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
|
),
|
||||||
|
Amount: '100',
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(
|
||||||
|
testContext.client,
|
||||||
|
paymentChannelClaim,
|
||||||
|
testContext.wallet,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
SettleDelay: 86400,
|
SettleDelay: 86400,
|
||||||
PublicKey: testContext.wallet.publicKey,
|
PublicKey: testContext.wallet.publicKey,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,28 @@ import {
|
|||||||
teardownClient,
|
teardownClient,
|
||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import { generateFundedWallet, testTransaction } from '../utils'
|
import { testTransaction } from '../utils'
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 20000
|
const TIMEOUT = 20000
|
||||||
const { hashPaymentChannel } = hashes
|
const { hashPaymentChannel } = hashes
|
||||||
|
|
||||||
describe('PaymentChannelFund', function () {
|
describe('PaymentChannelClaim', function () {
|
||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
testContext = await setupClient(serverUrl, true)
|
||||||
})
|
})
|
||||||
afterEach(async () => teardownClient(testContext))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'test xrp',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
Amount: '100',
|
Amount: '100',
|
||||||
Destination: wallet2.classicAddress,
|
Destination: testContext.destination.classicAddress,
|
||||||
SettleDelay: 86400,
|
SettleDelay: 86400,
|
||||||
PublicKey: testContext.wallet.publicKey,
|
PublicKey: testContext.wallet.publicKey,
|
||||||
}
|
}
|
||||||
@@ -36,6 +35,7 @@ describe('PaymentChannelFund', function () {
|
|||||||
paymentChannelCreate,
|
paymentChannelCreate,
|
||||||
{ wallet: testContext.wallet },
|
{ wallet: testContext.wallet },
|
||||||
)
|
)
|
||||||
|
|
||||||
await testTransaction(
|
await testTransaction(
|
||||||
testContext.client,
|
testContext.client,
|
||||||
paymentChannelCreate,
|
paymentChannelCreate,
|
||||||
@@ -47,7 +47,7 @@ describe('PaymentChannelFund', function () {
|
|||||||
TransactionType: 'PaymentChannelFund',
|
TransactionType: 'PaymentChannelFund',
|
||||||
Channel: hashPaymentChannel(
|
Channel: hashPaymentChannel(
|
||||||
testContext.wallet.classicAddress,
|
testContext.wallet.classicAddress,
|
||||||
wallet2.classicAddress,
|
testContext.destination.classicAddress,
|
||||||
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
),
|
),
|
||||||
Amount: '100',
|
Amount: '100',
|
||||||
@@ -61,4 +61,48 @@ describe('PaymentChannelFund', function () {
|
|||||||
},
|
},
|
||||||
TIMEOUT,
|
TIMEOUT,
|
||||||
)
|
)
|
||||||
|
it(
|
||||||
|
'test token',
|
||||||
|
async () => {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: testContext.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: testContext.wallet.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
const paymentChannelResponse = await testContext.client.submit(
|
||||||
|
paymentChannelCreate,
|
||||||
|
{ wallet: testContext.wallet },
|
||||||
|
)
|
||||||
|
|
||||||
|
const paymentChannelFund: PaymentChannelFund = {
|
||||||
|
Account: testContext.wallet.classicAddress,
|
||||||
|
TransactionType: 'PaymentChannelFund',
|
||||||
|
Channel: hashPaymentChannel(
|
||||||
|
testContext.wallet.classicAddress,
|
||||||
|
testContext.destination.classicAddress,
|
||||||
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
|
),
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: testContext.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(
|
||||||
|
testContext.client,
|
||||||
|
paymentChannelFund,
|
||||||
|
testContext.wallet,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
TIMEOUT,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user