mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-03 02:25:49 +00:00
implement Autofill Transaction (#1574)
Implements autofill() and setTransactionFlagsToNumber() to allow a Client to autofill fields in a Transaction.
This commit is contained in:
committed by
Mayukha Vadari
parent
949cc031ee
commit
04dd65af38
@@ -1,6 +1,21 @@
|
||||
/* eslint-disable no-bitwise -- flags require bitwise operations */
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { isFlagEnabled } from '../../src/models/utils'
|
||||
import {
|
||||
DepositPreauth,
|
||||
OfferCreate,
|
||||
OfferCreateFlagsEnum,
|
||||
PaymentChannelClaim,
|
||||
PaymentChannelClaimFlagsEnum,
|
||||
Payment,
|
||||
PaymentTransactionFlagsEnum,
|
||||
TrustSet,
|
||||
TrustSetFlagsEnum,
|
||||
} from '../../src/models/transactions'
|
||||
import {
|
||||
isFlagEnabled,
|
||||
setTransactionFlagsToNumber,
|
||||
} from '../../src/models/utils'
|
||||
|
||||
/**
|
||||
* Utils Testing.
|
||||
@@ -18,13 +33,120 @@ describe('Models Utils', function () {
|
||||
})
|
||||
|
||||
it('verifies a flag is enabled', function () {
|
||||
flags += flag1 + flag2
|
||||
flags |= flag1 | flag2
|
||||
assert.isTrue(isFlagEnabled(flags, flag1))
|
||||
})
|
||||
|
||||
it('verifies a flag is not enabled', function () {
|
||||
flags += flag2
|
||||
flags |= flag2
|
||||
assert.isFalse(isFlagEnabled(flags, flag1))
|
||||
})
|
||||
})
|
||||
|
||||
describe('setTransactionFlagsToNumber', function () {
|
||||
it('sets OfferCreateFlags to its numeric value', function () {
|
||||
const tx: OfferCreate = {
|
||||
Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W',
|
||||
Fee: '10',
|
||||
TakerGets: {
|
||||
currency: 'DSH',
|
||||
issuer: 'rcXY84C4g14iFp6taFXjjQGVeHqSCh9RX',
|
||||
value: '43.11584856965009',
|
||||
},
|
||||
TakerPays: '12928290425',
|
||||
TransactionType: 'OfferCreate',
|
||||
TxnSignature:
|
||||
'3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91',
|
||||
Flags: {
|
||||
tfPassive: true,
|
||||
tfImmediateOrCancel: false,
|
||||
tfFillOrKill: true,
|
||||
tfSell: false,
|
||||
},
|
||||
}
|
||||
|
||||
const { tfPassive, tfFillOrKill } = OfferCreateFlagsEnum
|
||||
const expected: number = tfPassive | tfFillOrKill
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
assert.strictEqual(tx.Flags, expected)
|
||||
})
|
||||
|
||||
it('sets PaymentChannelClaimFlags to its numeric value', function () {
|
||||
const tx: PaymentChannelClaim = {
|
||||
Account: 'r...',
|
||||
TransactionType: 'PaymentChannelClaim',
|
||||
Channel:
|
||||
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
|
||||
Flags: {
|
||||
tfRenew: true,
|
||||
tfClose: false,
|
||||
},
|
||||
}
|
||||
|
||||
const { tfRenew } = PaymentChannelClaimFlagsEnum
|
||||
const expected: number = tfRenew
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
assert.strictEqual(tx.Flags, expected)
|
||||
})
|
||||
|
||||
it('sets PaymentTransactionFlags to its numeric value', function () {
|
||||
const tx: Payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
|
||||
Amount: '1234',
|
||||
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
|
||||
Flags: {
|
||||
tfNoDirectRipple: false,
|
||||
tfPartialPayment: true,
|
||||
tfLimitQuality: true,
|
||||
},
|
||||
}
|
||||
|
||||
const { tfPartialPayment, tfLimitQuality } = PaymentTransactionFlagsEnum
|
||||
const expected: number = tfPartialPayment | tfLimitQuality
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
assert.strictEqual(tx.Flags, expected)
|
||||
})
|
||||
|
||||
it('sets TrustSetFlags to its numeric value', function () {
|
||||
const tx: TrustSet = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
|
||||
LimitAmount: {
|
||||
currency: 'XRP',
|
||||
issuer: 'rcXY84C4g14iFp6taFXjjQGVeHqSCh9RX',
|
||||
value: '4329.23',
|
||||
},
|
||||
QualityIn: 1234,
|
||||
QualityOut: 4321,
|
||||
Flags: {
|
||||
tfSetfAuth: true,
|
||||
tfSetNoRipple: false,
|
||||
tfClearNoRipple: true,
|
||||
tfSetFreeze: false,
|
||||
tfClearFreeze: true,
|
||||
},
|
||||
}
|
||||
|
||||
const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } = TrustSetFlagsEnum
|
||||
const expected: number = tfSetfAuth | tfClearNoRipple | tfClearFreeze
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
assert.strictEqual(tx.Flags, expected)
|
||||
})
|
||||
|
||||
it('sets other transaction types flags to its numeric value', function () {
|
||||
const tx: DepositPreauth = {
|
||||
TransactionType: 'DepositPreauth',
|
||||
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
|
||||
Flags: {},
|
||||
}
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
assert.strictEqual(tx.Flags, 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user