Update getNFTokenID to properly handle binary blob (#2247)

* Update NFTokenMint test

* Ensure the binary version works as well

* Remove meta being undefined in txResponse

* Remove error test

* Re-add test, error, and lint

* Add meta to test, and add string to allowed type

* Re-add meta being undefined with proper docs
This commit is contained in:
Jackson Mills
2023-06-23 16:17:29 -07:00
committed by GitHub
parent 6228f91c00
commit dc51e3a704
5 changed files with 98 additions and 59 deletions

View File

@@ -1,69 +1,87 @@
import { assert } from 'chai'
import _ from 'lodash'
import { Client } from 'xrpl'
import { TransactionMetadata, TxRequest } from 'xrpl'
import { convertStringToHex, getNFTokenID, NFTokenMint } from '../../../src'
import { hashSignedTx } from '../../../src/utils/hashes'
import serverUrl from '../serverUrl'
import {
convertStringToHex,
getNFTokenID,
NFTokenMint,
TransactionMetadata,
} from '../../../src'
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('NFTokenMint', function () {
// TODO: Once we update our integration tests to handle NFTs, replace this client with XrplIntegrationTestContext
let testContext: XrplIntegrationTestContext
beforeEach(async () => {
testContext = await setupClient(serverUrl)
})
afterEach(async () => teardownClient(testContext))
it(
'get NFTokenID',
async function () {
const client = new Client('wss://s.altnet.rippletest.net:51233/')
await client.connect()
const { wallet, balance: _balance } = await client.fundWallet(null, {
usageContext: 'integration-test',
})
const tx: NFTokenMint = {
TransactionType: 'NFTokenMint',
Account: wallet.address,
Account: testContext.wallet.address,
URI: convertStringToHex('https://www.google.com'),
NFTokenTaxon: 0,
}
try {
const response = await client.submitAndWait(tx, {
wallet,
})
assert.equal(response.type, 'response')
assert.equal(
(response.result.meta as TransactionMetadata).TransactionResult,
'tesSUCCESS',
)
const response = await testTransaction(
testContext.client,
tx,
testContext.wallet,
)
assert.equal(response.type, 'response')
const accountNFTs = await client.request({
command: 'account_nfts',
account: wallet.address,
})
const nftokenID =
getNFTokenID(response.result.meta as TransactionMetadata) ??
'undefined'
const accountHasNFT = accountNFTs.result.account_nfts.some(
(value) => value.NFTokenID === nftokenID,
)
assert.isTrue(
accountHasNFT,
`Expected to find an NFT with NFTokenID ${nftokenID} in account ${
wallet.address
} but did not find it.
\n\nHere's what was returned from 'account_nfts' for ${
wallet.address
}: ${JSON.stringify(accountNFTs)}`,
)
} finally {
await client.disconnect()
const txRequest: TxRequest = {
command: 'tx',
transaction: hashSignedTx(response.result.tx_blob),
}
const txResponse = await testContext.client.request(txRequest)
assert.equal(
(txResponse.result.meta as TransactionMetadata).TransactionResult,
'tesSUCCESS',
)
const accountNFTs = await testContext.client.request({
command: 'account_nfts',
account: testContext.wallet.address,
})
const nftokenID =
getNFTokenID(txResponse.result.meta as TransactionMetadata) ??
'undefined'
const accountHasNFT = accountNFTs.result.account_nfts.some(
(value) => value.NFTokenID === nftokenID,
)
assert.isTrue(
accountHasNFT,
`Expected to find an NFT with NFTokenID ${nftokenID} in account ${
testContext.wallet.address
} but did not find it.
\n\nHere's what was returned from 'account_nfts' for ${
testContext.wallet.address
}: ${JSON.stringify(accountNFTs)}`,
)
const binaryTxResponse = await testContext.client.request({
...txRequest,
binary: true,
})
assert.equal(
nftokenID,
getNFTokenID(binaryTxResponse.result.meta) ?? 'undefined',
`getNFTokenID produced a different outcome when decoding the metadata in binary format.`,
)
},
TIMEOUT,
)