Skip to content

Commit

Permalink
add test for withdrawal canonical ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
janmazak committed Jan 17, 2024
1 parent e23ddbe commit 09c8938
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/errors/invalidDataReason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export enum InvalidDataReason {
* typically resulting from a detailed analysis of key derivation paths
*/
LEDGER_POLICY = "Action rejected by Ledger's security policy",
// canonical ordering wrong (cannot be checked in LedgerJS for withdrawals)
INVALID_DATA_SUPPLIED_TO_LEDGER = 'Invalid data supplied to Ledger',

INVALID_B2_HASH = 'invalid blake2 hashing',
}
30 changes: 30 additions & 0 deletions test/integration/__fixtures__/signTxRejects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,36 @@ export const certificateStakePoolRetirementRejectTestCases: TestCaseRejectShelle
]

export const withdrawalRejectTestCases: TestCaseRejectShelley[] = [
{
testName:
'Reject tx with invalid canonical ordering of withdrawals',
// ledgerjs cannot validate this, so this test is only meaningful for a ledger device
tx: {
...mainnetFeeTtl,
inputs: [inputs.utxoShelley],
outputs: [],
withdrawals: [
{
amount: 33333,
stakeCredential: {
keyPath: [ 2147485500, 2147485463, 2147483648, 2, 1 ],
type: 0
}
},
{
amount: 33333,
stakeCredential: {
keyPath: [ 2147485500, 2147485463, 2147483648, 2, 0 ],
type: 0
}
},
]
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
errCls: DeviceStatusError,
errMsg: DeviceStatusMessages[DeviceStatusCodes.ERR_INVALID_DATA],
rejectReason: InvalidDataReason.INVALID_DATA_SUPPLIED_TO_LEDGER,
},
{
testName: 'Script hash as stake credential in Ordinary Tx',
tx: {
Expand Down
3 changes: 3 additions & 0 deletions test/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export function describeSignTxRejects(name: string, testList: any[]) {
if (rejectReason === InvalidDataReason.LEDGER_POLICY) {
return
}
if (rejectReason === InvalidDataReason.INVALID_DATA_SUPPLIED_TO_LEDGER) {
return
}
const response = ada.signTransaction({
tx,
signingMode,
Expand Down

0 comments on commit 09c8938

Please sign in to comment.