mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Round XRP fee to 6 decimal places (#912)
* Round XRP fee to 6 decimal places Fix #911
This commit is contained in:
@@ -74,10 +74,12 @@ async function getFee(
|
|||||||
|
|
||||||
const serverInfo = (await this.request('server_info')).info
|
const serverInfo = (await this.request('server_info')).info
|
||||||
const baseFeeXrp = new BigNumber(serverInfo.validated_ledger.base_fee_xrp)
|
const baseFeeXrp = new BigNumber(serverInfo.validated_ledger.base_fee_xrp)
|
||||||
const fee = baseFeeXrp.times(serverInfo.load_factor).times(cushion)
|
let fee = baseFeeXrp.times(serverInfo.load_factor).times(cushion)
|
||||||
|
|
||||||
// Cap fee to `this._maxFeeXRP`
|
// Cap fee to `this._maxFeeXRP`
|
||||||
return BigNumber.min(fee, this._maxFeeXRP).toString(10)
|
fee = BigNumber.min(fee, this._maxFeeXRP)
|
||||||
|
// Round fee to 6 decimal places
|
||||||
|
return (new BigNumber(fee.toFormat(6))).toString(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -1820,6 +1820,26 @@ describe('RippleAPI', function () {
|
|||||||
_.partial(checkResult, expectedResponse, 'prepare'));
|
_.partial(checkResult, expectedResponse, 'prepare'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('fee - calculated fee does not use more than 6 decimal places', function () {
|
||||||
|
this.api.connection._send(JSON.stringify({
|
||||||
|
command: 'config',
|
||||||
|
data: { loadFactor: 5407.96875 }
|
||||||
|
}));
|
||||||
|
|
||||||
|
const expectedResponse = {
|
||||||
|
"txJSON": "{\"Flags\":2147483648,\"TransactionType\":\"Payment\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Destination\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"Amount\":{\"value\":\"0.01\",\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},\"SendMax\":{\"value\":\"0.01\",\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\"},\"LastLedgerSequence\":8820051,\"Fee\":\"64896\",\"Sequence\":23}",
|
||||||
|
"instructions": {
|
||||||
|
"fee": "0.064896",
|
||||||
|
"sequence": 23,
|
||||||
|
"maxLedgerVersion": 8820051
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.api.preparePayment(
|
||||||
|
address, requests.preparePayment.normal, instructions).then(
|
||||||
|
_.partial(checkResult, expectedResponse, 'prepare'));
|
||||||
|
});
|
||||||
|
|
||||||
it('disconnect & isConnected', function () {
|
it('disconnect & isConnected', function () {
|
||||||
assert.strictEqual(this.api.isConnected(), true);
|
assert.strictEqual(this.api.isConnected(), true);
|
||||||
return this.api.disconnect().then(() => {
|
return this.api.disconnect().then(() => {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
|
|
||||||
mock.on('request_server_info', function (request, conn) {
|
mock.on('request_server_info', function (request, conn) {
|
||||||
assert.strictEqual(request.command, 'server_info');
|
assert.strictEqual(request.command, 'server_info');
|
||||||
if (conn.config.highLoadFactor) {
|
if (conn.config.highLoadFactor || conn.config.loadFactor) {
|
||||||
const response = {
|
const response = {
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"status": "success",
|
"status": "success",
|
||||||
@@ -167,7 +167,7 @@ module.exports = function createMockRippled(port) {
|
|||||||
"converge_time_s": 2.007,
|
"converge_time_s": 2.007,
|
||||||
"proposers": 4
|
"proposers": 4
|
||||||
},
|
},
|
||||||
"load_factor": 4294967296,
|
"load_factor": conn.config.loadFactor || 4294967296,
|
||||||
"peers": 53,
|
"peers": 53,
|
||||||
"pubkey_node": "n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC",
|
"pubkey_node": "n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC",
|
||||||
"server_state": "full",
|
"server_state": "full",
|
||||||
|
|||||||
Reference in New Issue
Block a user