mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 11:45:49 +00:00
feat: extra protection for AccountDelete transactions (#1626)
* add deletion blockers check to autofill * add tests * add fail_hard: true * pass in account_objects response to error * only fail_hard for AccountDelete * reject promise instead of throwing error * fix rebase issue
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { AccountDelete, EscrowFinish, Payment, Transaction } from 'xrpl-local'
|
||||
import {
|
||||
XrplError,
|
||||
AccountDelete,
|
||||
EscrowFinish,
|
||||
Payment,
|
||||
Transaction,
|
||||
} from 'xrpl-local'
|
||||
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertRejects } from '../testUtils'
|
||||
|
||||
const Fee = '10'
|
||||
const Sequence = 1432
|
||||
@@ -71,6 +78,27 @@ describe('client.autofill', function () {
|
||||
assert.strictEqual(txResult.Sequence, 23)
|
||||
})
|
||||
|
||||
it('should throw error if account deletion blockers exist', async function () {
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse(
|
||||
'account_objects',
|
||||
rippled.account_objects.normal,
|
||||
)
|
||||
|
||||
const tx: AccountDelete = {
|
||||
Account: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn',
|
||||
TransactionType: 'AccountDelete',
|
||||
Destination: 'X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ',
|
||||
Fee,
|
||||
Sequence,
|
||||
LastLedgerSequence,
|
||||
}
|
||||
|
||||
await assertRejects(this.client.autofill(tx), XrplError)
|
||||
})
|
||||
|
||||
describe('when autofill Fee is missing', function () {
|
||||
it('should autofill Fee of a Transaction', async function () {
|
||||
const tx: Transaction = {
|
||||
@@ -80,17 +108,7 @@ describe('client.autofill', function () {
|
||||
Sequence,
|
||||
LastLedgerSequence,
|
||||
}
|
||||
this.mockRippled.addResponse('server_info', {
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
info: {
|
||||
validated_ledger: {
|
||||
base_fee_xrp: 0.00001,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
const txResult = await this.client.autofill(tx)
|
||||
|
||||
assert.strictEqual(txResult.Fee, '12')
|
||||
@@ -108,19 +126,9 @@ describe('client.autofill', function () {
|
||||
}
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
|
||||
this.mockRippled.addResponse('server_info', {
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
info: {
|
||||
validated_ledger: {
|
||||
base_fee_xrp: 0.00001,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
const txResult = await this.client.autofill(tx)
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
|
||||
const txResult = await this.client.autofill(tx)
|
||||
assert.strictEqual(txResult.Fee, '399')
|
||||
})
|
||||
|
||||
@@ -132,17 +140,11 @@ describe('client.autofill', function () {
|
||||
}
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
|
||||
this.mockRippled.addResponse('server_info', {
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
info: {
|
||||
validated_ledger: {
|
||||
base_fee_xrp: 0.00001,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse(
|
||||
'account_objects',
|
||||
rippled.account_objects.empty,
|
||||
)
|
||||
const txResult = await this.client.autofill(tx)
|
||||
|
||||
assert.strictEqual(txResult.Fee, '5000000')
|
||||
@@ -160,17 +162,7 @@ describe('client.autofill', function () {
|
||||
}
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
|
||||
this.mockRippled.addResponse('server_info', {
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
info: {
|
||||
validated_ledger: {
|
||||
base_fee_xrp: 0.00001,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
const txResult = await this.client.autofill(tx, 4)
|
||||
|
||||
assert.strictEqual(txResult.Fee, '459')
|
||||
|
||||
13
test/fixtures/rippled/accountObjectsEmpty.json
vendored
Normal file
13
test/fixtures/rippled/accountObjectsEmpty.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": 1,
|
||||
"status": "success",
|
||||
"type": "response",
|
||||
"result": {
|
||||
"account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"account_objects": [],
|
||||
"ledger_hash":
|
||||
"053DF17D2289D1C4971C22F235BC1FCA7D4B3AE966F842E5819D0749E0B8ECD3",
|
||||
"ledger_index": 14378733,
|
||||
"validated": true
|
||||
}
|
||||
}
|
||||
3
test/fixtures/rippled/index.ts
vendored
3
test/fixtures/rippled/index.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import normalAccountInfo from './accountInfo.json'
|
||||
import notfoundAccountInfo from './accountInfoNotFound.json'
|
||||
import emptyAccountObjects from './accountObjectsEmpty.json'
|
||||
import normalAccountObjects from './accountObjectsNormal.json'
|
||||
import account_offers from './accountOffers'
|
||||
import normalAccountTx from './accountTx'
|
||||
@@ -133,7 +134,7 @@ const streams = {
|
||||
|
||||
const account_objects = {
|
||||
normal: normalAccountObjects,
|
||||
// notfound: notfoundAccountObjects
|
||||
empty: emptyAccountObjects,
|
||||
}
|
||||
|
||||
const account_info = {
|
||||
|
||||
Reference in New Issue
Block a user