mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 23:55:49 +00:00
refactor: define TrustSet transaction model (#1549)
- Defines a TypeScript type for TrustSet - Provides an optional function to users for verifying a TrustSet instance at runtime: verifyTrustSet() - Adds tests for verifyTrustSet()
This commit is contained in:
committed by
Mayukha Vadari
parent
2ff0dde91d
commit
d5d996a92e
66
test/models/trustSet.ts
Normal file
66
test/models/trustSet.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { ValidationError } from 'xrpl-local/common/errors'
|
||||
import { verifyTrustSet } from './../../src/models/transactions/trustSet'
|
||||
import { assert } from 'chai'
|
||||
|
||||
/**
|
||||
* TrustSet Transaction Verification Testing
|
||||
*
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('TrustSet Transaction Verification', () => {
|
||||
let trustSet
|
||||
|
||||
beforeEach(() => {
|
||||
trustSet = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
|
||||
LimitAmount: {
|
||||
currency: 'XRP',
|
||||
issuer: 'rcXY84C4g14iFp6taFXjjQGVeHqSCh9RX',
|
||||
value: '4329.23'
|
||||
},
|
||||
QualityIn: 1234,
|
||||
QualityOut: 4321,
|
||||
} as any
|
||||
})
|
||||
|
||||
it ('verifies valid TrustSet', () => {
|
||||
assert.doesNotThrow(() => verifyTrustSet(trustSet))
|
||||
})
|
||||
|
||||
it ('throws when LimitAmount is missing', () => {
|
||||
delete trustSet.LimitAmount
|
||||
assert.throws(
|
||||
() => verifyTrustSet(trustSet),
|
||||
ValidationError,
|
||||
'TrustSet: missing field LimitAmount'
|
||||
)
|
||||
})
|
||||
|
||||
it ('throws when LimitAmount is invalid', () => {
|
||||
trustSet.LimitAmount = 1234
|
||||
assert.throws(
|
||||
() => verifyTrustSet(trustSet),
|
||||
ValidationError,
|
||||
'TrustSet: invalid LimitAmount'
|
||||
)
|
||||
})
|
||||
|
||||
it ('throws when QualityIn is not a number', () => {
|
||||
trustSet.QualityIn = '1234'
|
||||
assert.throws(
|
||||
() => verifyTrustSet(trustSet),
|
||||
ValidationError,
|
||||
'TrustSet: QualityIn must be a number'
|
||||
)
|
||||
})
|
||||
|
||||
it ('throws when QualityOut is not a number', () => {
|
||||
trustSet.QualityOut = '4321'
|
||||
assert.throws(
|
||||
() => verifyTrustSet(trustSet),
|
||||
ValidationError,
|
||||
'TrustSet: QualityOut must be a number'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user