mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Support removing a signer list (#1021)
* Make weights an optional field * Fix #971
This commit is contained in:
@@ -94,7 +94,7 @@
|
||||
"maxItems": 8
|
||||
}
|
||||
},
|
||||
"required": ["threshold", "weights"],
|
||||
"required": ["threshold"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"transferRate": {
|
||||
|
||||
@@ -89,12 +89,17 @@ function createSettingsTransactionWithoutMemos(
|
||||
}
|
||||
|
||||
if (settings.signers !== undefined) {
|
||||
return {
|
||||
const setSignerList = {
|
||||
TransactionType: 'SignerListSet',
|
||||
Account: account,
|
||||
SignerQuorum: settings.signers.threshold,
|
||||
SignerEntries: settings.signers.weights.map(formatSignerEntry)
|
||||
SignerEntries: [],
|
||||
SignerQuorum: settings.signers.threshold
|
||||
};
|
||||
|
||||
if (settings.signers.weights !== undefined) {
|
||||
setSignerList.SignerEntries = settings.signers.weights.map(formatSignerEntry);
|
||||
}
|
||||
return setSignerList;
|
||||
}
|
||||
|
||||
const txJSON: SettingsTransaction = {
|
||||
|
||||
@@ -58,6 +58,11 @@ function prepareTransaction(txJSON: TransactionJSON, api: RippleAPI,
|
||||
'" exists in instance when not allowed'))
|
||||
}
|
||||
|
||||
// To remove the signer list, SignerEntries field should be omitted.
|
||||
if (txJSON['SignerQuorum'] === 0) {
|
||||
delete txJSON.SignerEntries;
|
||||
}
|
||||
|
||||
const account = txJSON.Account
|
||||
setCanonicalFlag(txJSON)
|
||||
|
||||
|
||||
@@ -1767,19 +1767,15 @@ describe('RippleAPI', function () {
|
||||
};
|
||||
});
|
||||
|
||||
it('prepareSettings - signers no weights', function (done) {
|
||||
it('prepareSettings - signers no weights', function () {
|
||||
const settings = requests.prepareSettings.signers.noWeights;
|
||||
try {
|
||||
this.api.prepareSettings(address, settings, instructionsWithMaxLedgerVersionOffset).then(prepared => {
|
||||
done(new Error('Expected method to reject. Prepared transaction: ' + JSON.stringify(prepared)));
|
||||
}).catch(err => {
|
||||
assert.strictEqual(err.name, 'ValidationError');
|
||||
assert.strictEqual(err.message, 'instance.settings.signers requires property "weights"');
|
||||
done();
|
||||
}).catch(done); // Finish test with assertion failure immediately instead of waiting for timeout.
|
||||
} catch (err) {
|
||||
done(new Error('Expected method to reject, but method threw. Thrown: ' + err));
|
||||
};
|
||||
const localInstructions = _.defaults({
|
||||
signersCount: 1
|
||||
}, instructionsWithMaxLedgerVersionOffset);
|
||||
return this.api.prepareSettings(
|
||||
address, settings, localInstructions).then(
|
||||
_.partial(checkResult, responses.prepareSettings.noWeights,
|
||||
'prepare'));
|
||||
});
|
||||
|
||||
it('prepareSettings - fee for multisign', function () {
|
||||
@@ -1792,6 +1788,17 @@ describe('RippleAPI', function () {
|
||||
'prepare'));
|
||||
});
|
||||
|
||||
it('prepareSettings - no signer list', function () {
|
||||
const settings = requests.prepareSettings.noSignerEntries;
|
||||
const localInstructions = _.defaults({
|
||||
signersCount: 1
|
||||
}, instructionsWithMaxLedgerVersionOffset);
|
||||
return this.api.prepareSettings(
|
||||
address, settings, localInstructions).then(
|
||||
_.partial(checkResult, responses.prepareSettings.noSignerList,
|
||||
'prepare'));
|
||||
});
|
||||
|
||||
it('prepareSettings - invalid', function (done) {
|
||||
// domain must be a string
|
||||
const settings = Object.assign({},
|
||||
|
||||
1
test/fixtures/requests/index.js
vendored
1
test/fixtures/requests/index.js
vendored
@@ -22,6 +22,7 @@ module.exports = {
|
||||
},
|
||||
prepareSettings: {
|
||||
domain: require('./prepare-settings'),
|
||||
noSignerEntries: require('./prepare-settings-no-signer-entries'),
|
||||
signers: {
|
||||
normal: require('./prepare-settings-signers'),
|
||||
noThreshold: require('./prepare-settings-signers-no-threshold'),
|
||||
|
||||
5
test/fixtures/requests/prepare-settings-no-signer-entries.json
vendored
Normal file
5
test/fixtures/requests/prepare-settings-no-signer-entries.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"signers": {
|
||||
"threshold": 0
|
||||
}
|
||||
}
|
||||
4
test/fixtures/responses/index.js
vendored
4
test/fixtures/responses/index.js
vendored
@@ -122,7 +122,9 @@ module.exports = {
|
||||
noInstructions: require('./prepare-settings-no-instructions.json'),
|
||||
signed: require('./prepare-settings-signed.json'),
|
||||
noMaxLedgerVersion: require('./prepare-settings-no-maxledgerversion.json'),
|
||||
signers: require('./prepare-settings-signers.json')
|
||||
signers: require('./prepare-settings-signers.json'),
|
||||
noSignerList: require('./prepare-settings-no-signer-list.json'),
|
||||
noWeights: require('./prepare-settings-no-weight.json')
|
||||
},
|
||||
prepareCheckCreate: {
|
||||
normal: require('./prepare-check-create'),
|
||||
|
||||
8
test/fixtures/responses/prepare-settings-no-signer-list.json
vendored
Normal file
8
test/fixtures/responses/prepare-settings-no-signer-list.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"txJSON": "{\"TransactionType\":\"SignerListSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"SignerQuorum\":0,\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Fee\":\"24\",\"Sequence\":23}",
|
||||
"instructions": {
|
||||
"fee": "0.000024",
|
||||
"sequence": 23,
|
||||
"maxLedgerVersion": 8820051
|
||||
}
|
||||
}
|
||||
8
test/fixtures/responses/prepare-settings-no-weight.json
vendored
Normal file
8
test/fixtures/responses/prepare-settings-no-weight.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"txJSON": "{\"TransactionType\":\"SignerListSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"SignerQuorum\":2,\"SignerEntries\":[],\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Fee\":\"24\",\"Sequence\":23}",
|
||||
"instructions": {
|
||||
"fee": "0.000024",
|
||||
"sequence": 23,
|
||||
"maxLedgerVersion": 8820051
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user