Skip to content

Commit

Permalink
add integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
khancode committed Feb 6, 2025
1 parent c1e3a80 commit e9dbc6e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
50 changes: 50 additions & 0 deletions packages/xrpl/test/integration/transactions/ammClawback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { AMMClawback, AMMDeposit, AMMDepositFlags } from 'xrpl'

import serverUrl from '../serverUrl'
import {
setupClient,
teardownClient,
type XrplIntegrationTestContext,
} from '../setup'
import { createAMMPool, testTransaction } from '../utils'

describe('AMMClawback', function () {
let testContext: XrplIntegrationTestContext

beforeAll(async () => {
testContext = await setupClient(serverUrl)
})
afterAll(async () => teardownClient(testContext))

it('base', async function () {
const ammPool = await createAMMPool(testContext.client, true)
const { asset, asset2, issuerWallet } = ammPool
const holderWallet = ammPool.lpWallet

const ammDepositTx: AMMDeposit = {
TransactionType: 'AMMDeposit',
Account: holderWallet.classicAddress,
Asset: asset,
Asset2: asset2,
Amount: {
currency: 'USD',
issuer: issuerWallet.address,
value: '10',
},
Flags: AMMDepositFlags.tfSingleAsset,
}

await testTransaction(testContext.client, ammDepositTx, holderWallet)

const ammClawback: AMMClawback = {
TransactionType: 'AMMClawback',
Account: issuerWallet.address,
Holder: holderWallet.address,
// @ts-expect-error -- this is an IssuedCurrency
Asset: asset,
Asset2: asset2,
}

await testTransaction(testContext.client, ammClawback, issuerWallet)
})
})
13 changes: 11 additions & 2 deletions packages/xrpl/test/integration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ export async function getIOUBalance(
return (await client.request(request)).result.lines[0].balance
}

export async function createAMMPool(client: Client): Promise<{
export async function createAMMPool(
client: Client,
enableClawback = false,
): Promise<{
issuerWallet: Wallet
lpWallet: Wallet
asset: Currency
Expand All @@ -383,10 +386,16 @@ export async function createAMMPool(client: Client): Promise<{
const issuerWallet = await generateFundedWallet(client)
const currencyCode = 'USD'

let accountSetFlags = AccountSetAsfFlags.asfDefaultRipple
if (enableClawback) {
// eslint-disable-next-line no-bitwise -- required
accountSetFlags |= AccountSetAsfFlags.asfAllowTrustLineClawback
}

const accountSetTx: AccountSet = {
TransactionType: 'AccountSet',
Account: issuerWallet.classicAddress,
SetFlag: AccountSetAsfFlags.asfDefaultRipple,
SetFlag: accountSetFlags,
}

await testTransaction(client, accountSetTx, issuerWallet)
Expand Down

0 comments on commit e9dbc6e

Please sign in to comment.