mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Merge branch 'develop' into connection-cleanup-tests
This commit is contained in:
@@ -354,6 +354,16 @@ export default <TestSuite>{
|
||||
)
|
||||
},
|
||||
|
||||
'AccountDelete': async (api, address) => {
|
||||
const hash = 'EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9'
|
||||
const response = await api.getTransaction(hash)
|
||||
assertResultMatch(
|
||||
response,
|
||||
RESPONSE_FIXTURES.accountDelete,
|
||||
'getTransaction'
|
||||
)
|
||||
},
|
||||
|
||||
'no Meta': async (api, address) => {
|
||||
const hash =
|
||||
'AFB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B'
|
||||
|
||||
@@ -745,6 +745,33 @@ export default <TestSuite>{
|
||||
return assertResultMatch(response, expected, 'prepare')
|
||||
},
|
||||
|
||||
'AccountDelete': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '5.0' // 5 XRP fee for AccountDelete
|
||||
}
|
||||
|
||||
const txJSON = {
|
||||
TransactionType: 'AccountDelete',
|
||||
Account: address,
|
||||
Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe'
|
||||
}
|
||||
|
||||
const response = await api.prepareTransaction(txJSON, localInstructions)
|
||||
const expected = {
|
||||
txJSON:
|
||||
'{"TransactionType":"AccountDelete","Account":"' +
|
||||
address +
|
||||
'","Destination":"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe","Flags":2147483648,"LastLedgerSequence":8820051,"Fee":"12","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051
|
||||
}
|
||||
}
|
||||
return assertResultMatch(response, expected, 'prepare')
|
||||
},
|
||||
|
||||
// prepareTransaction - Payment
|
||||
'Payment - normal': async (api, address) => {
|
||||
const localInstructions = {
|
||||
|
||||
@@ -212,7 +212,7 @@ export default <TestSuite>{
|
||||
) => {
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
// TODO: This fails when address is X-Address
|
||||
// TODO: This fails when address is X-address
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1.2","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '0.0000012',
|
||||
@@ -232,7 +232,7 @@ export default <TestSuite>{
|
||||
) => {
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
// TODO: This fails when address is X-Address
|
||||
// TODO: This fails when address is X-address
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"1123456.7","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '1.1234567',
|
||||
@@ -289,7 +289,7 @@ export default <TestSuite>{
|
||||
api._maxFeeXRP = '2.1'
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
// TODO: This fails when address is X-Address
|
||||
// TODO: This fails when address is X-address
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '2.01',
|
||||
|
||||
@@ -220,6 +220,30 @@ describe('Connection', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('DisconnectedError on initial _onOpen send', async function() {
|
||||
// _onOpen previously could throw PromiseRejectionHandledWarning: Promise rejection was handled asynchronously
|
||||
// do not rely on the api.setup hook to test this as it bypasses the case, disconnect api connection first
|
||||
await this.api.disconnect();
|
||||
|
||||
// stub _onOpen to only run logic relevant to test case
|
||||
this.api.connection._onOpen = () => {
|
||||
// overload websocket send on open when _ws exists
|
||||
this.api.connection._ws.send = function(data, options, cb) {
|
||||
// recent ws throws this error instead of calling back
|
||||
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
||||
}
|
||||
const request = {command: 'subscribe', streams: ['ledger']};
|
||||
return this.api.connection.request(request);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.api.connect();
|
||||
} catch (error) {
|
||||
assert(error instanceof this.api.errors.DisconnectedError);
|
||||
assert.strictEqual(error.message, 'WebSocket is not open: readyState 0 (CONNECTING)');
|
||||
}
|
||||
});
|
||||
|
||||
it('ResponseFormatError', function() {
|
||||
return this.api
|
||||
.request('test_command', {data: {unrecognizedResponse: true}})
|
||||
|
||||
32
test/fixtures/responses/get-transaction-account-delete.json
vendored
Normal file
32
test/fixtures/responses/get-transaction-account-delete.json
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"type": "accountDelete",
|
||||
"address": "rM5qup5BYDLMXaR5KU1hiC9HhFMuBVrnKv",
|
||||
"sequence": 3227049,
|
||||
"id": "EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9",
|
||||
"specification": {
|
||||
"destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
"destinationXAddress": "XV5kHfQmzDQjbFNv4jX3FX9Y7ig5QhpKGEFCq4mdLfhdxMq"
|
||||
},
|
||||
"outcome": {
|
||||
"result": "tesSUCCESS",
|
||||
"timestamp": "2019-12-17T09:16:51.000Z",
|
||||
"fee": "5",
|
||||
"balanceChanges": {
|
||||
"rM5qup5BYDLMXaR5KU1hiC9HhFMuBVrnKv": [
|
||||
{
|
||||
"currency": "XRP",
|
||||
"value": "-10000"
|
||||
}
|
||||
],
|
||||
"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe": [
|
||||
{
|
||||
"currency": "XRP",
|
||||
"value": "9995"
|
||||
}
|
||||
]
|
||||
},
|
||||
"orderbookChanges": {},
|
||||
"ledgerVersion": 3232071,
|
||||
"indexInLedger": 0
|
||||
}
|
||||
}
|
||||
3
test/fixtures/responses/index.js
vendored
3
test/fixtures/responses/index.js
vendored
@@ -67,7 +67,8 @@ module.exports = {
|
||||
paymentChannelClaim:
|
||||
require('./get-transaction-payment-channel-claim.json'),
|
||||
amendment: require('./get-transaction-amendment.json'),
|
||||
feeUpdate: require('./get-transaction-fee-update.json')
|
||||
feeUpdate: require('./get-transaction-fee-update.json'),
|
||||
accountDelete: require('./get-transaction-account-delete.json')
|
||||
},
|
||||
getTransactions: {
|
||||
normal: require('./get-transactions.json'),
|
||||
|
||||
3
test/fixtures/rippled/index.js
vendored
3
test/fixtures/rippled/index.js
vendored
@@ -99,6 +99,7 @@ module.exports = {
|
||||
NoMeta: require('./tx/no-meta.json'),
|
||||
LedgerZero: require('./tx/ledger-zero.json'),
|
||||
Amendment: require('./tx/amendment.json'),
|
||||
SetFee: require('./tx/set-fee.json')
|
||||
SetFee: require('./tx/set-fee.json'),
|
||||
AccountDelete: require('./tx/account-delete.json')
|
||||
}
|
||||
};
|
||||
|
||||
66
test/fixtures/rippled/tx/account-delete.json
vendored
Normal file
66
test/fixtures/rippled/tx/account-delete.json
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"id": 0,
|
||||
"result": {
|
||||
"Account": "rM5qup5BYDLMXaR5KU1hiC9HhFMuBVrnKv",
|
||||
"Destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
"Fee": "5000000",
|
||||
"Flags": 2147483648,
|
||||
"LastLedgerSequence": 3232818,
|
||||
"Sequence": 3227049,
|
||||
"SigningPubKey": "022E0DBF14BC4CFF96BC839557EE6F12F6DA45DCD917376F805E65D1B1C60A8CE6",
|
||||
"TransactionType": "AccountDelete",
|
||||
"TxnSignature": "304402207BDBE1B71C8BD00363905817C9373880CE9E8F0080623D457495E2B760BBBEE402202EDEB977D1ED865C1EAB88FE28581E3F8A672097B8BB0956E977C6EC87CA668C",
|
||||
"date": 629889411,
|
||||
"hash": "EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9",
|
||||
"inLedger": 3232071,
|
||||
"ledger_index": 3232071,
|
||||
"meta": {
|
||||
"AffectedNodes": [
|
||||
{
|
||||
"DeletedNode": {
|
||||
"FinalFields": {
|
||||
"Account": "rM5qup5BYDLMXaR5KU1hiC9HhFMuBVrnKv",
|
||||
"Balance": "0",
|
||||
"Flags": 0,
|
||||
"OwnerCount": 0,
|
||||
"PreviousTxnID": "2737BEDDDA1D7FB523CFB84B891216331CC4CC999349828D81C6C727A1115A44",
|
||||
"PreviousTxnLgrSeq": 3227049,
|
||||
"Sequence": 3227050
|
||||
},
|
||||
"LedgerEntryType": "AccountRoot",
|
||||
"LedgerIndex": "08EBF94D7BB527442E0B51F533B902DDCFBD423D8E95FAE752BE7876A29E875B",
|
||||
"PreviousFields": {
|
||||
"Balance": "10000000000",
|
||||
"Sequence": 3227049
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ModifiedNode": {
|
||||
"FinalFields": {
|
||||
"Account": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
"Balance": "99991026734967448",
|
||||
"Flags": 0,
|
||||
"OwnerCount": 0,
|
||||
"Sequence": 2978
|
||||
},
|
||||
"LedgerEntryType": "AccountRoot",
|
||||
"LedgerIndex": "31CCE9D28412FF973E9AB6D0FA219BACF19687D9A2456A0C2ABC3280E9D47E37",
|
||||
"PreviousFields": {
|
||||
"Balance": "99991016739967448"
|
||||
},
|
||||
"PreviousTxnID": "2737BEDDDA1D7FB523CFB84B891216331CC4CC999349828D81C6C727A1115A44",
|
||||
"PreviousTxnLgrSeq": 3227049
|
||||
}
|
||||
}
|
||||
],
|
||||
"DeliveredAmount": "9995000000",
|
||||
"TransactionIndex": 0,
|
||||
"TransactionResult": "tesSUCCESS",
|
||||
"delivered_amount": "9995000000"
|
||||
},
|
||||
"validated": true
|
||||
},
|
||||
"status": "success",
|
||||
"type": "response"
|
||||
}
|
||||
@@ -553,6 +553,11 @@ export function createMockRippled(port) {
|
||||
'81B9ECAE7195EB6E8034AEDF44D8415A7A803E14513FDBB34FA984AB37D59563'
|
||||
) {
|
||||
conn.send(createResponse(request, fixtures.tx.PaymentChannelClaim))
|
||||
} else if (
|
||||
request.transaction ===
|
||||
'EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9'
|
||||
) {
|
||||
conn.send(createResponse(request, fixtures.tx.AccountDelete))
|
||||
} else if (
|
||||
request.transaction ===
|
||||
'AFB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11'
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('RippleAPI [Test Runner]', function() {
|
||||
})
|
||||
// Run each test with the newer, x-address style.
|
||||
if (!config.skipXAddress) {
|
||||
describe(`[X-Address]`, () => {
|
||||
describe(`[X-address]`, () => {
|
||||
for (const [testName, fn] of tests) {
|
||||
it(testName, function() {
|
||||
return fn(this.api, addresses.ACCOUNT_X)
|
||||
|
||||
@@ -33,7 +33,7 @@ interface LoadedTestSuite {
|
||||
name: string
|
||||
tests: [string, TestFn][]
|
||||
config: {
|
||||
/** Set to true to skip re-running tests with an X-Address. */
|
||||
/** Set to true to skip re-running tests with an X-address. */
|
||||
skipXAddress?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user