mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
feat: add sidechain-specific RPCs/sugar (#1940)
* federator_info responses/requests * edit docstring * make strings narrower * export federator_info * implement createXchainPayment * add tests * fix dependency cycle * fix linter errors * rename xchain -> crosschain * rename more * edit HISTORY * fix docstrings * add another test
This commit is contained in:
127
packages/xrpl/test/utils/createCrossChainPayment.ts
Normal file
127
packages/xrpl/test/utils/createCrossChainPayment.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { assert } from 'chai'
|
||||
import {
|
||||
createCrossChainPayment,
|
||||
convertStringToHex,
|
||||
Payment,
|
||||
} from 'xrpl-local'
|
||||
|
||||
describe('createCrossChainPayment', function () {
|
||||
it('successful xchain payment creation', function () {
|
||||
const payment: Payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rRandom',
|
||||
Destination: 'rRandom2',
|
||||
Amount: '3489303',
|
||||
}
|
||||
const sidechainAccount = 'rSidechain'
|
||||
|
||||
const expectedPayment = {
|
||||
...payment,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoData: convertStringToHex(sidechainAccount),
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const resultPayment = createCrossChainPayment(payment, sidechainAccount)
|
||||
assert.deepEqual(resultPayment, expectedPayment)
|
||||
|
||||
// ensure that the original object wasn't modified
|
||||
assert.notDeepEqual(resultPayment, payment)
|
||||
})
|
||||
|
||||
it('successful xchain payment creation with memo', function () {
|
||||
const memo = {
|
||||
Memo: {
|
||||
MemoData: 'deadbeef',
|
||||
},
|
||||
}
|
||||
const payment: Payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rRandom',
|
||||
Destination: 'rRandom2',
|
||||
Amount: '3489303',
|
||||
Memos: [memo],
|
||||
}
|
||||
const sidechainAccount = 'rSidechain'
|
||||
|
||||
const expectedPayment = {
|
||||
...payment,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoData: convertStringToHex(sidechainAccount),
|
||||
},
|
||||
},
|
||||
memo,
|
||||
],
|
||||
}
|
||||
|
||||
const resultPayment = createCrossChainPayment(payment, sidechainAccount)
|
||||
assert.deepEqual(resultPayment, expectedPayment)
|
||||
|
||||
// ensure that the original object wasn't modified
|
||||
assert.notDeepEqual(resultPayment, payment)
|
||||
})
|
||||
|
||||
it('removes TxnSignature', function () {
|
||||
const payment: Payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rRandom',
|
||||
Destination: 'rRandom2',
|
||||
Amount: '3489303',
|
||||
TxnSignature: 'asodfiuaosdfuaosd',
|
||||
}
|
||||
const sidechainAccount = 'rSidechain'
|
||||
|
||||
const expectedPayment = {
|
||||
...payment,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoData: convertStringToHex(sidechainAccount),
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
delete expectedPayment.TxnSignature
|
||||
|
||||
const resultPayment = createCrossChainPayment(payment, sidechainAccount)
|
||||
assert.deepEqual(resultPayment, expectedPayment)
|
||||
|
||||
// ensure that the original object wasn't modified
|
||||
assert.notDeepEqual(resultPayment, payment)
|
||||
})
|
||||
|
||||
it('fails with 3 memos', function () {
|
||||
const payment: Payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rRandom',
|
||||
Destination: 'rRandom2',
|
||||
Amount: '3489303',
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoData: '2934723843ace',
|
||||
},
|
||||
},
|
||||
{
|
||||
Memo: {
|
||||
MemoData: '2934723843ace',
|
||||
},
|
||||
},
|
||||
{
|
||||
Memo: {
|
||||
MemoData: '2934723843ace',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
assert.throws(() => {
|
||||
createCrossChainPayment(payment, 'rSidechain')
|
||||
}, /Cannot have more than 2 memos/u)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user