mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
refactor: define typescript type for AccountSet transaction (#1515)
* define typescript type for AccountSet transaction
This commit is contained in:
committed by
Mayukha Vadari
parent
930d214107
commit
72f34d9388
110
test/models/accountSet.ts
Normal file
110
test/models/accountSet.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { ValidationError } from 'xrpl-local/common/errors'
|
||||
import { verifyAccountSet } from './../../src/models/transactions/accountSet'
|
||||
import { assert } from 'chai'
|
||||
|
||||
/**
|
||||
* AccountSet Transaction Verification Testing
|
||||
*
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('AccountSet Transaction Verification', function () {
|
||||
|
||||
let account
|
||||
|
||||
beforeEach(() => {
|
||||
account = {
|
||||
TransactionType : "AccountSet",
|
||||
Account : "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
Fee : "12",
|
||||
Sequence : 5,
|
||||
Domain : "6578616D706C652E636F6D",
|
||||
SetFlag : 5,
|
||||
MessageKey : "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB"
|
||||
} as any
|
||||
})
|
||||
|
||||
it (`verifies valid AccountSet`, () => {
|
||||
assert.doesNotThrow(() => verifyAccountSet(account))
|
||||
})
|
||||
|
||||
it (`throws w/ invalid SetFlag (out of range)`, () => {
|
||||
account.SetFlag = 12
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid SetFlag"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid SetFlag (incorrect type)`, () => {
|
||||
account.SetFlag = 'abc'
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid SetFlag"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid ClearFlag`, () => {
|
||||
account.ClearFlag = 12
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid ClearFlag"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid Domain`, () => {
|
||||
account.Domain = 6578616
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid Domain"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid EmailHash`, () => {
|
||||
account.EmailHash = 657861645678909876543456789876543
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid EmailHash"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid MessageKey`, () => {
|
||||
account.MessageKey = 65786165678908765456789567890678
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid MessageKey"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid TransferRate`, () => {
|
||||
account.TransferRate = "1000000001"
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid TransferRate"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid TickSize`, () => {
|
||||
account.TickSize = 20
|
||||
|
||||
assert.throws(
|
||||
() => verifyAccountSet(account),
|
||||
ValidationError,
|
||||
"AccountSet: invalid TickSize"
|
||||
)
|
||||
})
|
||||
|
||||
})
|
||||
@@ -7,7 +7,7 @@ import { assert } from 'chai'
|
||||
*
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('CheckCancel Transaction Verification', function () {
|
||||
describe('Transaction Verification', function () {
|
||||
|
||||
it (`verifies valid CheckCancel`, () => {
|
||||
const validCheckCancel = {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { ValidationError } from 'xrpl-local/common/errors'
|
||||
import { verifyOfferCancel } from './../../src/models/transactions/offerCancel'
|
||||
import { assert } from 'chai'
|
||||
|
||||
/**
|
||||
* OfferCancel Transaction Verification Testing
|
||||
*
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('OfferCancel Transaction Verification', function () {
|
||||
let offer
|
||||
|
||||
beforeEach(() => {
|
||||
offer = {
|
||||
Account: "rnKiczmiQkZFiDES8THYyLA2pQohC5C6EF",
|
||||
Fee: "10",
|
||||
LastLedgerSequence: 65477334,
|
||||
OfferSequence: 60797528,
|
||||
Sequence: 60797535,
|
||||
SigningPubKey: "0361BFD43D1EEA54B77CC152887312949EBF052997FBFFCDAF6F2653164B55B21...",
|
||||
TransactionType: "OfferCancel",
|
||||
TxnSignature: "30450221008C43BDCFC68B4793857CA47DF454C07E5B45D3F80E8E6785CAB9292...",
|
||||
date: "2021-08-06T21:04:11Z"
|
||||
} as any
|
||||
})
|
||||
|
||||
it (`verifies valid OfferCancel`, () => {
|
||||
assert.doesNotThrow(() => verifyOfferCancel(offer))
|
||||
})
|
||||
|
||||
it (`verifies valid OfferCancel with flags`, () => {
|
||||
offer.Flags = 2147483648
|
||||
assert.doesNotThrow(() => verifyOfferCancel(offer))
|
||||
})
|
||||
|
||||
it (`throws w/ invalid OfferSequence`, () => {
|
||||
offer.OfferSequence = '99'
|
||||
assert.throws(
|
||||
() => verifyOfferCancel(offer),
|
||||
ValidationError,
|
||||
"OfferCancel: invalid OfferSequence"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ missing OfferSequence`, () => {
|
||||
delete offer.OfferSequence
|
||||
assert.throws(
|
||||
() => verifyOfferCancel(offer),
|
||||
ValidationError,
|
||||
"OfferCancel: missing field OfferSequence"
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -8,9 +8,10 @@ import { assert } from 'chai'
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('SignerListSet Transaction Verification', function () {
|
||||
|
||||
it (`verifies valid SignerListSet`, () => {
|
||||
const validSignerListSet = {
|
||||
let SignerListSetTx
|
||||
|
||||
beforeEach(() => {
|
||||
SignerListSetTx = {
|
||||
Flags: 0,
|
||||
TransactionType: "SignerListSet",
|
||||
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
@@ -37,72 +38,38 @@ describe('SignerListSet Transaction Verification', function () {
|
||||
}
|
||||
]
|
||||
} as any
|
||||
|
||||
assert.doesNotThrow(() => verifySignerListSet(validSignerListSet))
|
||||
})
|
||||
|
||||
it (`verifies valid SignerListSet`, () => {
|
||||
assert.doesNotThrow(() => verifySignerListSet(SignerListSetTx))
|
||||
})
|
||||
|
||||
|
||||
it (`throws w/ missing SignerQuorum`, () => {
|
||||
const invalidSignerQuorum = {
|
||||
Flags: 0,
|
||||
TransactionType: "SignerListSet",
|
||||
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
SignerEntries: [
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
|
||||
SignerWeight: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
|
||||
SignerWeight: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: "raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n",
|
||||
SignerWeight: 1
|
||||
}
|
||||
}
|
||||
]
|
||||
} as any
|
||||
SignerListSetTx.SignerQuorum = undefined
|
||||
|
||||
assert.throws(
|
||||
() => verifySignerListSet(invalidSignerQuorum),
|
||||
() => verifySignerListSet(SignerListSetTx),
|
||||
ValidationError,
|
||||
"SignerListSet: missing field SignerQuorum"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ empty SignerEntries`, () => {
|
||||
const emptySignerEntries = {
|
||||
Flags: 0,
|
||||
TransactionType: "SignerListSet",
|
||||
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
SignerQuorum: 3,
|
||||
SignerEntries: []
|
||||
} as any
|
||||
SignerListSetTx.SignerEntries = []
|
||||
|
||||
assert.throws(
|
||||
() => verifySignerListSet(emptySignerEntries),
|
||||
() => verifySignerListSet(SignerListSetTx),
|
||||
ValidationError,
|
||||
"SignerListSet: need atleast 1 member in SignerEntries"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid SignerEntries`, () => {
|
||||
const invalidSignerEntries = {
|
||||
Flags: 0,
|
||||
TransactionType: "SignerListSet",
|
||||
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
SignerQuorum: 3,
|
||||
SignerEntries: "khgfgyhujk"
|
||||
} as any
|
||||
|
||||
SignerListSetTx.SignerEntries = "khgfgyhujk"
|
||||
|
||||
assert.throws(
|
||||
() => verifySignerListSet(invalidSignerEntries),
|
||||
() => verifySignerListSet(SignerListSetTx),
|
||||
ValidationError,
|
||||
"SignerListSet: invalid SignerEntries"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user