add integration tests

This commit is contained in:
Denis Angell
2023-02-14 19:28:48 -05:00
parent f3ec0f654e
commit 7efc525fa2
5 changed files with 341 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
import { assert } from 'chai'
import { convertStringToHex, URITokenMint, URITokenBurn } from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('URITokenMint', function () {
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'base',
async () => {
const tx: URITokenMint = {
TransactionType: 'URITokenMint',
Account: testContext.wallet.classicAddress,
URI: convertStringToHex('ipfs://CID'),
}
await testTransaction(testContext.client, tx, testContext.wallet)
// check that the object was actually created
const mintResponse = await testContext.client.request({
command: 'account_objects',
account: testContext.wallet.classicAddress,
})
assert.equal(mintResponse.result.account_objects.length, 1)
const uriTokenID = mintResponse.result.account_objects[0].index
assert.isString(uriTokenID)
const burnTx: URITokenBurn = {
TransactionType: 'URITokenBurn',
Account: testContext.wallet.classicAddress,
URITokenID: uriTokenID,
}
await testTransaction(testContext.client, burnTx, 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,
0,
)
},
TIMEOUT,
)
})

View File

@@ -0,0 +1,95 @@
import { assert } from 'chai'
import { URITokenBuy } from '../../../dist/npm'
import {
convertStringToHex,
URITokenMint,
URITokenSell,
xrpToDrops,
} from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { generateFundedWallet, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('URITokenSell', function () {
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'base',
async () => {
const wallet1 = await generateFundedWallet(testContext.client)
const tx: URITokenMint = {
TransactionType: 'URITokenMint',
Account: testContext.wallet.classicAddress,
URI: convertStringToHex('ipfs://CID'),
}
await testTransaction(testContext.client, tx, testContext.wallet)
// check that the object was actually created
const mintResponse = await testContext.client.request({
command: 'account_objects',
account: testContext.wallet.classicAddress,
})
assert.equal(mintResponse.result.account_objects.length, 1)
const uriTokenID = mintResponse.result.account_objects[0].index
assert.isString(uriTokenID)
const sellTx: URITokenSell = {
TransactionType: 'URITokenCreateSellOffer',
Account: testContext.wallet.classicAddress,
URITokenID: uriTokenID,
Amount: xrpToDrops(10),
}
await testTransaction(testContext.client, sellTx, testContext.wallet)
// verify amount is on le
const buyTx: URITokenBuy = {
TransactionType: 'URITokenBuy',
Account: wallet1.classicAddress,
URITokenID: uriTokenID,
Amount: xrpToDrops(10),
}
await testTransaction(testContext.client, buyTx, wallet1)
// check that wallet1 owns uritoken
assert.equal(
(
await testContext.client.request({
command: 'account_objects',
account: wallet1.classicAddress,
})
).result.account_objects.length,
1,
)
// check that wallet1 does not own uritoken
assert.equal(
(
await testContext.client.request({
command: 'account_objects',
account: testContext.wallet.classicAddress,
})
).result.account_objects.length,
0,
)
},
TIMEOUT,
)
})

View File

@@ -0,0 +1,72 @@
import { assert } from 'chai'
import { URITokenClear } from '../../../dist/npm'
import {
convertStringToHex,
URITokenMint,
URITokenSell,
xrpToDrops,
} from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('URITokenSell', function () {
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'base',
async () => {
const tx: URITokenMint = {
TransactionType: 'URITokenMint',
Account: testContext.wallet.classicAddress,
URI: convertStringToHex('ipfs://CID'),
}
await testTransaction(testContext.client, tx, testContext.wallet)
// check that the object was actually created
const mintResponse = await testContext.client.request({
command: 'account_objects',
account: testContext.wallet.classicAddress,
})
assert.equal(mintResponse.result.account_objects.length, 1)
const uriTokenID = mintResponse.result.account_objects[0].index
assert.isString(uriTokenID)
const sellTx: URITokenSell = {
TransactionType: 'URITokenCreateSellOffer',
Account: testContext.wallet.classicAddress,
URITokenID: uriTokenID,
Amount: xrpToDrops(10),
}
await testTransaction(testContext.client, sellTx, testContext.wallet)
// verify amount is on le
const clearTx: URITokenClear = {
TransactionType: 'URITokenCancelSellOffer',
Account: testContext.wallet.classicAddress,
URITokenID: uriTokenID,
}
await testTransaction(testContext.client, clearTx, testContext.wallet)
// verify amount is not on le
},
TIMEOUT,
)
})

View File

@@ -0,0 +1,47 @@
import { assert } from 'chai'
import { convertStringToHex, URITokenMint } from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('URITokenMint', function () {
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'base',
async () => {
const tx: URITokenMint = {
TransactionType: 'URITokenMint',
Account: testContext.wallet.classicAddress,
URI: convertStringToHex('ipfs://CID'),
}
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,
1,
)
},
TIMEOUT,
)
})

View File

@@ -0,0 +1,62 @@
import { assert } from 'chai'
import {
convertStringToHex,
URITokenMint,
URITokenSell,
xrpToDrops,
} from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('URITokenSell', function () {
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'base',
async () => {
const tx: URITokenMint = {
TransactionType: 'URITokenMint',
Account: testContext.wallet.classicAddress,
URI: convertStringToHex('ipfs://CID'),
}
await testTransaction(testContext.client, tx, testContext.wallet)
// check that the object was actually created
const mintResponse = await testContext.client.request({
command: 'account_objects',
account: testContext.wallet.classicAddress,
})
assert.equal(mintResponse.result.account_objects.length, 1)
const uriTokenID = mintResponse.result.account_objects[0].index
assert.isString(uriTokenID)
const sellTx: URITokenSell = {
TransactionType: 'URITokenCreateSellOffer',
Account: testContext.wallet.classicAddress,
URITokenID: uriTokenID,
Amount: xrpToDrops(10),
}
await testTransaction(testContext.client, sellTx, testContext.wallet)
// verify amount is on le
},
TIMEOUT,
)
})