mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
refactor: define SignerListSet model and tests (#1538)
* define typescript type for SignerListSet transaction
This commit is contained in:
committed by
Mayukha Vadari
parent
e27e1ec368
commit
1cc23c6ba9
@@ -40,3 +40,8 @@ interface PathStep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Path = PathStep[]
|
export type Path = PathStep[]
|
||||||
|
|
||||||
|
export interface SignerEntry {
|
||||||
|
Account: string;
|
||||||
|
SignerWeight: number;
|
||||||
|
}
|
||||||
@@ -3,3 +3,4 @@ export * from './offerCreate'
|
|||||||
export * from './checkCreate'
|
export * from './checkCreate'
|
||||||
export * from './checkCash'
|
export * from './checkCash'
|
||||||
export * from './checkCancel'
|
export * from './checkCancel'
|
||||||
|
export * from './signerListSet'
|
||||||
38
src/models/transactions/signerListSet.ts
Normal file
38
src/models/transactions/signerListSet.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { ValidationError } from "../../common/errors"
|
||||||
|
import { SignerEntry } from "../common"
|
||||||
|
import { BaseTransaction, verifyBaseTransaction } from "./common"
|
||||||
|
|
||||||
|
export interface SignerListSet extends BaseTransaction {
|
||||||
|
TransactionType: "SignerListSet"
|
||||||
|
SignerQuorum: number
|
||||||
|
SignerEntries: SignerEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an SignerListSet at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An SignerListSet Transaction
|
||||||
|
* @returns - Void.
|
||||||
|
* @throws - When the SignerListSet is Malformed.
|
||||||
|
*/
|
||||||
|
export function verifySignerListSet(tx: SignerListSet): void {
|
||||||
|
verifyBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.SignerQuorum === undefined)
|
||||||
|
throw new ValidationError("SignerListSet: missing field SignerQuorum")
|
||||||
|
|
||||||
|
if (typeof tx.SignerQuorum !== 'number')
|
||||||
|
throw new ValidationError("SignerListSet: invalid SignerQuorum")
|
||||||
|
|
||||||
|
if (tx.SignerEntries === undefined)
|
||||||
|
throw new ValidationError("SignerListSet: missing field SignerEntries")
|
||||||
|
|
||||||
|
if (!Array.isArray(tx.SignerEntries))
|
||||||
|
throw new ValidationError("SignerListSet: invalid SignerEntries")
|
||||||
|
|
||||||
|
if (tx.SignerEntries.length === 0)
|
||||||
|
throw new ValidationError("SignerListSet: need atleast 1 member in SignerEntries")
|
||||||
|
|
||||||
|
if (tx.SignerEntries.length > 8)
|
||||||
|
throw new ValidationError("SignerListSet: maximum of 8 members allowed in SignerEntries")
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { OfferCreate } from "./offerCreate";
|
|||||||
import { CheckCash } from "./checkCash";
|
import { CheckCash } from "./checkCash";
|
||||||
import { CheckCancel } from "./checkCancel";
|
import { CheckCancel } from "./checkCancel";
|
||||||
import { CheckCreate } from "./checkCreate";
|
import { CheckCreate } from "./checkCreate";
|
||||||
|
import { SignerListSet } from "./signerListSet";
|
||||||
|
|
||||||
export type Transaction =
|
export type Transaction =
|
||||||
// AccountSet
|
// AccountSet
|
||||||
@@ -21,7 +22,7 @@ export type Transaction =
|
|||||||
// | PaymentChannelCreate
|
// | PaymentChannelCreate
|
||||||
// | PaymentChannelFund
|
// | PaymentChannelFund
|
||||||
// | SetRegularKey
|
// | SetRegularKey
|
||||||
// | SignerListSet
|
| SignerListSet
|
||||||
// | TicketCreate
|
// | TicketCreate
|
||||||
// | TrustSet
|
// | TrustSet
|
||||||
|
|
||||||
|
|||||||
110
test/models/signerListSet.ts
Normal file
110
test/models/signerListSet.ts
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import { ValidationError } from 'ripple-api/common/errors'
|
||||||
|
import { verifySignerListSet } from './../../src/models/transactions/signerListSet'
|
||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SignerListSet Transaction Verification Testing
|
||||||
|
*
|
||||||
|
* Providing runtime verification testing for each specific transaction type
|
||||||
|
*/
|
||||||
|
describe('SignerListSet Transaction Verification', function () {
|
||||||
|
|
||||||
|
it (`verifies valid SignerListSet`, () => {
|
||||||
|
const validSignerListSet = {
|
||||||
|
Flags: 0,
|
||||||
|
TransactionType: "SignerListSet",
|
||||||
|
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
Fee: "12",
|
||||||
|
SignerQuorum: 3,
|
||||||
|
SignerEntries: [
|
||||||
|
{
|
||||||
|
SignerEntry: {
|
||||||
|
Account: "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
|
||||||
|
SignerWeight: 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SignerEntry: {
|
||||||
|
Account: "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
|
||||||
|
SignerWeight: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SignerEntry: {
|
||||||
|
Account: "raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n",
|
||||||
|
SignerWeight: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.doesNotThrow(() => verifySignerListSet(validSignerListSet))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifySignerListSet(invalidSignerQuorum),
|
||||||
|
ValidationError,
|
||||||
|
"SignerListSet: missing field SignerQuorum"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ empty SignerEntries`, () => {
|
||||||
|
const emptySignerEntries = {
|
||||||
|
Flags: 0,
|
||||||
|
TransactionType: "SignerListSet",
|
||||||
|
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
SignerQuorum: 3,
|
||||||
|
SignerEntries: []
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifySignerListSet(emptySignerEntries),
|
||||||
|
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
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifySignerListSet(invalidSignerEntries),
|
||||||
|
ValidationError,
|
||||||
|
"SignerListSet: invalid SignerEntries"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user