diff --git a/src/models/transactions/index.ts b/src/models/transactions/index.ts index f2aa4999..84117b52 100644 --- a/src/models/transactions/index.ts +++ b/src/models/transactions/index.ts @@ -14,6 +14,7 @@ export * from './paymentTransaction' export * from './paymentChannelClaim' export * from './paymentChannelCreate' export * from './paymentChannelFund' +export * from './setRegularKey' export * from './signerListSet' export * from './ticketCreate' export * from './trustSet' diff --git a/src/models/transactions/setRegularKey.ts b/src/models/transactions/setRegularKey.ts new file mode 100644 index 00000000..d01caa36 --- /dev/null +++ b/src/models/transactions/setRegularKey.ts @@ -0,0 +1,19 @@ +import { ValidationError } from "../../common/errors" +import { BaseTransaction, verifyBaseTransaction } from "./common" + +export interface SetRegularKey extends BaseTransaction { + TransactionType: "SetRegularKey" + RegularKey?: string +} + +/** + * @param {SetRegularKey} tx A Payment Transaction. + * @returns {void} + * @throws {ValidationError} When the SetRegularKey is malformed. + */ + export function verifySetRegularKey(tx: SetRegularKey): void { + verifyBaseTransaction(tx) + + if (tx.RegularKey !== undefined && typeof tx.RegularKey !== 'string') + throw new ValidationError("SetRegularKey: RegularKey must be a string") +} \ No newline at end of file diff --git a/src/models/transactions/transaction.ts b/src/models/transactions/transaction.ts index e21c7369..22c8600a 100644 --- a/src/models/transactions/transaction.ts +++ b/src/models/transactions/transaction.ts @@ -14,6 +14,7 @@ import { PaymentTransaction } from "./paymentTransaction" import { PaymentChannelClaim } from './paymentChannelClaim' import { PaymentChannelCreate } from "./paymentChannelCreate" import { PaymentChannelFund } from "./paymentChannelFund" +import { SetRegularKey } from "./setRegularKey"; import { SignerListSet } from "./signerListSet" import { TicketCreate } from "./ticketCreate" import { TrustSet } from "./trustSet" @@ -34,7 +35,7 @@ export type Transaction = | PaymentChannelClaim | PaymentChannelCreate | PaymentChannelFund -// | SetRegularKey + | SetRegularKey | SignerListSet | TicketCreate | TrustSet diff --git a/test/models/setRegularKey.ts b/test/models/setRegularKey.ts new file mode 100644 index 00000000..e8a8fc87 --- /dev/null +++ b/test/models/setRegularKey.ts @@ -0,0 +1,42 @@ +import { ValidationError } from 'xrpl-local/common/errors' +import { verifySetRegularKey } from './../../src/models/transactions/setRegularKey' +import { assert } from 'chai' + +/** + * SetRegularKey Transaction Verification Testing + * + * Providing runtime verification testing for each specific transaction type + */ +describe('SetRegularKey Transaction Verification', function () { + let account + + beforeEach(() => { + account = { + TransactionType : "SetRegularKey", + Account : "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + Fee : "12", + Flags : 0, + RegularKey : "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD" + } as any + }) + + it (`verifies valid SetRegularKey`, () => { + assert.doesNotThrow(() => verifySetRegularKey(account)) + }) + + it (`verifies w/o SetRegularKey`, () => { + account.RegularKey = undefined + assert.doesNotThrow(() => verifySetRegularKey(account)) + }) + + it (`throws w/ invalid RegularKey`, () => { + account.RegularKey = 12369846963 + + assert.throws( + () => verifySetRegularKey(account), + ValidationError, + "SetRegularKey: RegularKey must be a string" + ) + }) + +}) \ No newline at end of file