mirror of
				https://github.com/Xahau/xahau.js.git
				synced 2025-11-04 04:55:48 +00:00 
			
		
		
		
	Co-authored-by: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Co-authored-by: Denis Angell <dangell@transia.co>
		
			
				
	
	
		
			113 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { assert } from 'chai'
 | 
						|
 | 
						|
import { OfferCreate, TrustSet, Wallet } from '../../../src'
 | 
						|
import serverUrl from '../serverUrl'
 | 
						|
import {
 | 
						|
  setupClient,
 | 
						|
  teardownClient,
 | 
						|
  type XrplIntegrationTestContext,
 | 
						|
} from '../setup'
 | 
						|
import {
 | 
						|
  testTransaction,
 | 
						|
  generateFundedWallet,
 | 
						|
  submitTransaction,
 | 
						|
} from '../utils'
 | 
						|
 | 
						|
// how long before each test case times out
 | 
						|
const TIMEOUT = 20000
 | 
						|
 | 
						|
describe('OfferCreate', function () {
 | 
						|
  let testContext: XrplIntegrationTestContext
 | 
						|
  let wallet_deep_freeze_trustline: Wallet | undefined
 | 
						|
 | 
						|
  beforeAll(async () => {
 | 
						|
    testContext = await setupClient(serverUrl)
 | 
						|
    if (!wallet_deep_freeze_trustline) {
 | 
						|
      // eslint-disable-next-line require-atomic-updates -- race condition doesn't really matter
 | 
						|
      wallet_deep_freeze_trustline = await generateFundedWallet(
 | 
						|
        testContext.client,
 | 
						|
      )
 | 
						|
    }
 | 
						|
  })
 | 
						|
 | 
						|
  afterAll(async () => teardownClient(testContext))
 | 
						|
 | 
						|
  it(
 | 
						|
    'base',
 | 
						|
    async () => {
 | 
						|
      const tx: OfferCreate = {
 | 
						|
        TransactionType: 'OfferCreate',
 | 
						|
        Account: testContext.wallet.classicAddress,
 | 
						|
        TakerGets: '13100000',
 | 
						|
        TakerPays: {
 | 
						|
          currency: 'USD',
 | 
						|
          issuer: testContext.wallet.classicAddress,
 | 
						|
          value: '10',
 | 
						|
        },
 | 
						|
      }
 | 
						|
 | 
						|
      await testTransaction(testContext.client, tx, testContext.wallet)
 | 
						|
 | 
						|
      // confirm that the offer actually went through
 | 
						|
      const accountOffersResponse = await testContext.client.request({
 | 
						|
        command: 'account_offers',
 | 
						|
        account: testContext.wallet.classicAddress,
 | 
						|
      })
 | 
						|
      assert.lengthOf(
 | 
						|
        accountOffersResponse.result.offers!,
 | 
						|
        1,
 | 
						|
        'Should be exactly one offer on the ledger',
 | 
						|
      )
 | 
						|
    },
 | 
						|
    TIMEOUT,
 | 
						|
  )
 | 
						|
 | 
						|
  it(
 | 
						|
    'OfferCreate with Deep-Frozen trustline must fail',
 | 
						|
    async () => {
 | 
						|
      assert(wallet_deep_freeze_trustline != null)
 | 
						|
 | 
						|
      // deep-freeze the trust line
 | 
						|
      const trust_set_tx: TrustSet = {
 | 
						|
        TransactionType: 'TrustSet',
 | 
						|
        Account: testContext.wallet.classicAddress,
 | 
						|
        LimitAmount: {
 | 
						|
          currency: 'USD',
 | 
						|
          issuer: wallet_deep_freeze_trustline.classicAddress,
 | 
						|
          value: '10',
 | 
						|
        },
 | 
						|
        Flags: {
 | 
						|
          tfSetFreeze: true,
 | 
						|
          tfSetDeepFreeze: true,
 | 
						|
        },
 | 
						|
      }
 | 
						|
 | 
						|
      await testTransaction(
 | 
						|
        testContext.client,
 | 
						|
        trust_set_tx,
 | 
						|
        testContext.wallet,
 | 
						|
      )
 | 
						|
 | 
						|
      const offer_create_tx: OfferCreate = {
 | 
						|
        TransactionType: 'OfferCreate',
 | 
						|
        Account: testContext.wallet.classicAddress,
 | 
						|
        TakerGets: '13100000',
 | 
						|
        TakerPays: {
 | 
						|
          currency: 'USD',
 | 
						|
          issuer: wallet_deep_freeze_trustline.classicAddress,
 | 
						|
          value: '10',
 | 
						|
        },
 | 
						|
      }
 | 
						|
 | 
						|
      const response = await submitTransaction({
 | 
						|
        client: testContext.client,
 | 
						|
        transaction: offer_create_tx,
 | 
						|
        wallet: testContext.wallet,
 | 
						|
      })
 | 
						|
 | 
						|
      assert.equal(response.result.engine_result, 'tecFROZEN')
 | 
						|
    },
 | 
						|
    TIMEOUT,
 | 
						|
  )
 | 
						|
})
 |