mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-05 16:58:01 +00:00
Don't set empty paths
"The Paths field must not be an empty array, nor an array whose members are all empty arrays." https://ripple.com/build/transactions/#paths Fix test file lint errors
This commit is contained in:
@@ -344,8 +344,8 @@ Transaction.prototype._computeFee = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (fees.length) {
|
switch (fees.length) {
|
||||||
case 0: return undefined;
|
case 0: return undefined;
|
||||||
case 1: return String(fees[0]);
|
case 1: return String(fees[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fees.sort(function ascending(a, b) {
|
fees.sort(function ascending(a, b) {
|
||||||
@@ -1181,6 +1181,10 @@ Transaction.prototype.paths = function(paths) {
|
|||||||
throw new Error('Paths must be an array');
|
throw new Error('Paths must be an array');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (paths.length === 0) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
this.tx_json.Paths = [];
|
this.tx_json.Paths = [];
|
||||||
paths.forEach(this.addPath, this);
|
paths.forEach(this.addPath, this);
|
||||||
|
|
||||||
|
|||||||
@@ -649,26 +649,26 @@ describe('Transaction', function() {
|
|||||||
Paths: [
|
Paths: [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
account: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
account: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
issuer: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
issuer: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||||
type: 49,
|
type: 49,
|
||||||
type_hex: '0000000000000031'
|
type_hex: '0000000000000031'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
currency: 'LTC',
|
currency: 'LTC',
|
||||||
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
type: 48,
|
type: 48,
|
||||||
type_hex: '0000000000000030'
|
type_hex: '0000000000000030'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
account: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
account: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
currency: 'LTC',
|
currency: 'LTC',
|
||||||
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
type: 49,
|
type: 49,
|
||||||
type_hex: '0000000000000031'
|
type_hex: '0000000000000031'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
SendMax: {
|
SendMax: {
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
@@ -778,26 +778,26 @@ describe('Transaction', function() {
|
|||||||
Paths: [
|
Paths: [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
account: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
account: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
issuer: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
issuer: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||||
type: 49,
|
type: 49,
|
||||||
type_hex: '0000000000000031'
|
type_hex: '0000000000000031'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
currency: 'LTC',
|
currency: 'LTC',
|
||||||
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
type: 48,
|
type: 48,
|
||||||
type_hex: '0000000000000030'
|
type_hex: '0000000000000030'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
account: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
account: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
currency: 'LTC',
|
currency: 'LTC',
|
||||||
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
issuer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||||
type: 49,
|
type: 49,
|
||||||
type_hex: '0000000000000031'
|
type_hex: '0000000000000031'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
SendMax: {
|
SendMax: {
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
@@ -1136,17 +1136,17 @@ describe('Transaction', function() {
|
|||||||
|
|
||||||
const paths = [
|
const paths = [
|
||||||
[{
|
[{
|
||||||
account: 'rP51ycDJw5ZhgvdKiRjBYZKYjsyoCcHmnY',
|
account: 'rP51ycDJw5ZhgvdKiRjBYZKYjsyoCcHmnY',
|
||||||
issuer: 'rsLEU1TPdCJPPysqhWYw9jD97xtG5WqSJm',
|
issuer: 'rsLEU1TPdCJPPysqhWYw9jD97xtG5WqSJm',
|
||||||
test: 1,
|
test: 1,
|
||||||
currency: 'USD'
|
currency: 'USD'
|
||||||
}],
|
}],
|
||||||
[{
|
[{
|
||||||
account: 'rP51ycDJw5ZhgvdKiRjBYZKYjsyoCcHmnY',
|
account: 'rP51ycDJw5ZhgvdKiRjBYZKYjsyoCcHmnY',
|
||||||
issuer: 'rsLEU1TPdCJPPysqhWYw9jD97xtG5WqSJm',
|
issuer: 'rsLEU1TPdCJPPysqhWYw9jD97xtG5WqSJm',
|
||||||
test: 2,
|
test: 2,
|
||||||
currency: 'USD'
|
currency: 'USD'
|
||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
|
|
||||||
// assert.throws(function() {
|
// assert.throws(function() {
|
||||||
@@ -1184,6 +1184,27 @@ describe('Transaction', function() {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Does not add empty transaction paths', function() {
|
||||||
|
const transaction = new Transaction();
|
||||||
|
|
||||||
|
const paths = [];
|
||||||
|
|
||||||
|
assert.strictEqual(transaction.tx_json.Paths, undefined);
|
||||||
|
|
||||||
|
transaction.setType('Payment');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
transaction.paths(1);
|
||||||
|
}, /Error: Paths must be an array/);
|
||||||
|
assert.throws(function() {
|
||||||
|
transaction.setPaths(1);
|
||||||
|
}, /Error: Paths must be an array/);
|
||||||
|
|
||||||
|
transaction.setPaths(paths);
|
||||||
|
|
||||||
|
assert.strictEqual(transaction.tx_json.Paths, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('Set secret', function() {
|
it('Set secret', function() {
|
||||||
const transaction = new Transaction();
|
const transaction = new Transaction();
|
||||||
transaction.secret('shHXjwp9m3MDQNcUrTekXcdzFsCjM');
|
transaction.secret('shHXjwp9m3MDQNcUrTekXcdzFsCjM');
|
||||||
|
|||||||
Reference in New Issue
Block a user