mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-04 21:15:47 +00:00
* create credentials obj, modify depositpreauth * structrure of transaction models * initial validation methods and modify transactions affected by deposit auth * cleanup and add new transactions to list * binarycodec and add amendments to config * methods account for credentials * binary codec update * add amendments to config * error validation for credentials actions * core logic of error validation completed * type checking in error validation * init test files and field type validations * basic tests for crud transactions * cred delete tests * cred accept unit tests * cred create and accept unit tests * cred delete unit tests * depositPreauth unit tests * generic checks for payment, paymentchannelclaim, escrowfinish credential list * ledger entry update * lint errors * cleanup and use helper methods * fix lint bug * init integration tests for new transactions * fix build error, integration test docker update * unit test fixes -- all pass now * integration test layout complete * integration command * integration tests run * cicd command edit * lint and cleanup * modified history markdown * deposit preauth integration update * update docs with new docker command * fix validation for string id credential arrays * exports * add flag * lint * fix typo in contributing doc * docstring typos * readable string * fix test' * review comment fixes * txn duplicate fix * Apply suggestions from code review Co-authored-by: Omar Khan <khancodegt@gmail.com> Co-authored-by: Mayukha Vadari <mvadari@ripple.com> * Apply suggestions from code review Co-authored-by: Omar Khan <khancodegt@gmail.com> * Apply suggestions from code review Co-authored-by: Omar Khan <khancodegt@gmail.com> Co-authored-by: Mayukha Vadari <mvadari@ripple.com> * typo in auto suggest * rebase * readd definitions after rebase * cleanup list val * unit tests fixed and running * lint * refactor authcred check to work * Update packages/xrpl/src/models/transactions/payment.ts Co-authored-by: Omar Khan <khancodegt@gmail.com> * typo * Update .ci-config/rippled.cfg Co-authored-by: Omar Khan <khancodegt@gmail.com> * update rippled version * optional field nits * add to response depositauthorize * Update packages/xrpl/src/models/transactions/CredentialCreate.ts Co-authored-by: Omar Khan <khancodegt@gmail.com> * Update packages/xrpl/src/models/transactions/CredentialDelete.ts Co-authored-by: Omar Khan <khancodegt@gmail.com> * Update packages/xrpl/src/models/transactions/accountDelete.ts Co-authored-by: Omar Khan <khancodegt@gmail.com> * Apply suggestions from code review Co-authored-by: Omar Khan <khancodegt@gmail.com> * cleanups * unit test fix * more escrowfinish tests * clearer error message * re add statement * undo autodeleted mandates * remove extraneous integration tests for now * lint * Update .ci-config/rippled.cfg Co-authored-by: Omar Khan <khancodegt@gmail.com> * Update packages/xrpl/src/models/transactions/common.ts Co-authored-by: Omar Khan <khancodegt@gmail.com> * added tests * typo --------- Co-authored-by: Omar Khan <khancodegt@gmail.com> Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
197 lines
5.4 KiB
TypeScript
197 lines
5.4 KiB
TypeScript
import { assert } from 'chai'
|
|
|
|
import {
|
|
Payment,
|
|
Wallet,
|
|
MPTokenIssuanceCreate,
|
|
MPTokenAuthorize,
|
|
TransactionMetadata,
|
|
} 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('Payment', function () {
|
|
let testContext: XrplIntegrationTestContext
|
|
let paymentTx: Payment
|
|
const AMOUNT = '10000000'
|
|
// This wallet is used for DeliverMax related tests
|
|
let senderWallet: Wallet
|
|
|
|
beforeEach(async () => {
|
|
// this payment transaction JSON needs to be refreshed before every test.
|
|
// Because, we tinker with Amount and DeliverMax fields in the API v2 tests
|
|
paymentTx = {
|
|
TransactionType: 'Payment',
|
|
Account: senderWallet.classicAddress,
|
|
Amount: AMOUNT,
|
|
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
|
|
}
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
testContext = await setupClient(serverUrl)
|
|
senderWallet = await generateFundedWallet(testContext.client)
|
|
})
|
|
afterAll(async () => teardownClient(testContext))
|
|
|
|
it(
|
|
'base',
|
|
async () => {
|
|
const tx: Payment = {
|
|
TransactionType: 'Payment',
|
|
Account: testContext.wallet.classicAddress,
|
|
Destination: senderWallet.classicAddress,
|
|
Amount: '1000',
|
|
}
|
|
await testTransaction(testContext.client, tx, testContext.wallet)
|
|
},
|
|
TIMEOUT,
|
|
)
|
|
|
|
it(
|
|
'Validate Payment transaction API v2: Payment Transaction: Specify Only Amount field',
|
|
async () => {
|
|
const result = await testTransaction(
|
|
testContext.client,
|
|
paymentTx,
|
|
senderWallet,
|
|
)
|
|
|
|
assert.equal(result.result.engine_result_code, 0)
|
|
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
|
|
},
|
|
TIMEOUT,
|
|
)
|
|
|
|
it(
|
|
'Validate Payment transaction API v2: Payment Transaction: Specify Only DeliverMax field',
|
|
async () => {
|
|
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
|
|
paymentTx.DeliverMax = paymentTx.Amount
|
|
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
|
|
delete paymentTx.Amount
|
|
|
|
const result = await testTransaction(
|
|
testContext.client,
|
|
paymentTx,
|
|
senderWallet,
|
|
)
|
|
|
|
assert.equal(result.result.engine_result_code, 0)
|
|
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
|
|
},
|
|
TIMEOUT,
|
|
)
|
|
|
|
it(
|
|
'Validate Payment transaction API v2: Payment Transaction: identical DeliverMax and Amount fields',
|
|
async () => {
|
|
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
|
|
paymentTx.DeliverMax = paymentTx.Amount
|
|
|
|
const result = await testTransaction(
|
|
testContext.client,
|
|
paymentTx,
|
|
senderWallet,
|
|
)
|
|
|
|
assert.equal(result.result.engine_result_code, 0)
|
|
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
|
|
},
|
|
TIMEOUT,
|
|
)
|
|
|
|
it(
|
|
'Validate MPT Payment ',
|
|
async () => {
|
|
const wallet2 = await generateFundedWallet(testContext.client)
|
|
|
|
const createTx: MPTokenIssuanceCreate = {
|
|
TransactionType: 'MPTokenIssuanceCreate',
|
|
Account: testContext.wallet.classicAddress,
|
|
}
|
|
|
|
const mptCreateRes = await testTransaction(
|
|
testContext.client,
|
|
createTx,
|
|
testContext.wallet,
|
|
)
|
|
|
|
const txHash = mptCreateRes.result.tx_json.hash
|
|
|
|
const txResponse = await testContext.client.request({
|
|
command: 'tx',
|
|
transaction: txHash,
|
|
})
|
|
|
|
const meta = txResponse.result
|
|
.meta as TransactionMetadata<MPTokenIssuanceCreate>
|
|
|
|
const mptID = meta.mpt_issuance_id!
|
|
|
|
let accountObjectsResponse = await testContext.client.request({
|
|
command: 'account_objects',
|
|
account: testContext.wallet.classicAddress,
|
|
type: 'mpt_issuance',
|
|
})
|
|
assert.lengthOf(
|
|
accountObjectsResponse.result.account_objects,
|
|
1,
|
|
'Should be exactly one issuance on the ledger',
|
|
)
|
|
|
|
const authTx: MPTokenAuthorize = {
|
|
TransactionType: 'MPTokenAuthorize',
|
|
Account: wallet2.classicAddress,
|
|
MPTokenIssuanceID: mptID,
|
|
}
|
|
|
|
await testTransaction(testContext.client, authTx, wallet2)
|
|
|
|
accountObjectsResponse = await testContext.client.request({
|
|
command: 'account_objects',
|
|
account: wallet2.classicAddress,
|
|
type: 'mptoken',
|
|
})
|
|
|
|
assert.lengthOf(
|
|
accountObjectsResponse.result.account_objects,
|
|
1,
|
|
'Holder owns 1 MPToken on the ledger',
|
|
)
|
|
|
|
const payTx: Payment = {
|
|
TransactionType: 'Payment',
|
|
Account: testContext.wallet.classicAddress,
|
|
Destination: wallet2.classicAddress,
|
|
Amount: {
|
|
mpt_issuance_id: mptID,
|
|
value: '100',
|
|
},
|
|
}
|
|
|
|
await testTransaction(testContext.client, payTx, testContext.wallet)
|
|
|
|
accountObjectsResponse = await testContext.client.request({
|
|
command: 'account_objects',
|
|
account: testContext.wallet.classicAddress,
|
|
type: 'mpt_issuance',
|
|
})
|
|
assert.equal(
|
|
// @ts-expect-error -- Object type not known
|
|
accountObjectsResponse.result.account_objects[0].OutstandingAmount,
|
|
`100`,
|
|
)
|
|
},
|
|
TIMEOUT,
|
|
)
|
|
})
|