forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable-master-test.js
157 lines (140 loc) · 5.12 KB
/
disable-master-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
let assert = require('assert-diff');
let async = require('async');
let Remote = require('ripple-lib').Remote;
let testutils = require('./testutils');
testutils.init_config();
suite('Disabling MasterKey', function() {
let $ = {};
setup(function(done) {
testutils.build_setup().call($, function() {
$.remote.local_signing = true;
done();
});
});
teardown(function(done) {
testutils.build_teardown().call($, done);
});
test('lsfPasswordSpent', function(done) {
let password_spent_flag = Remote.flags.account_root.PasswordSpent;
let regular_key = 'rGLnRYhy5fQK5pxZuMxtsJKrbu5onBpRst';
async.series(
[
function(callback) {
testutils.create_accounts($.remote, 'root', '1000.0', ['alice'], callback);
},
function(callback) {
$.remote.requestAccountInfo({account: 'alice'}, function(err, info) {
assert.ifError(err);
assert(!(info.account_data.Flags & password_spent_flag),
'PasswordSpent flag set unexpectedly');
callback();
});
},
function(callback) {
let tx = $.remote.createTransaction('SetRegularKey', {
account: 'alice',
regular_key: regular_key
});
// As a special feature, each account is allowed to perform
// SetRegularKey transaction without a transaction fee as long as
// the lsfPasswordSpent flag for the account is not set
//
// https://github.com/ripple/rippled/blob/4239880acb5e559446d2067f00dabb31cf102a23/src/ripple/app/transactors/SetRegularKey.cpp#L64-L67
tx.setFixedFee(0);
tx.once('submitted', function(res) {
assert.strictEqual(res.engine_result, 'tesSUCCESS');
});
testutils.submit_transaction(tx, callback);
},
function(callback) {
$.remote.requestAccountInfo({account: 'alice'}, function(err, info) {
assert.ifError(err);
assert(info.account_data.Flags & password_spent_flag,
'PasswordSpent flag not set');
callback();
});
},
function(callback) {
// The second SetRegularKey transaction with Fee=0 should fail.
// The initial engine_result is telINSUF_FEE_P. ripple-lib waits for the
// transaction's LastLedgerSequence to expire, so the final result is a
// locally-determined failure: tejMaxLedger
let tx = $.remote.createTransaction('SetRegularKey', {
account: 'alice',
regular_key: regular_key
});
tx.setFixedFee(0);
tx.once('submitted', function(res) {
assert.strictEqual(res.engine_result, 'telINSUF_FEE_P');
});
testutils.submit_transaction(tx, function(err) {
assert(err);
assert.strictEqual(err.result, 'tejMaxLedger');
callback();
});
},
function(callback) {
let tx = $.remote.createTransaction('Payment', {
account: 'root',
destination: 'alice',
amount: '1'
});
testutils.submit_transaction(tx, function(err, res) {
assert.ifError(err);
assert.strictEqual(res.engine_result, 'tesSUCCESS');
callback();
});
},
function(callback) {
$.remote.requestAccountInfo({account: 'alice'}, function(err, info) {
assert.ifError(err);
assert(!(info.account_data.Flags & password_spent_flag),
'PasswordSpent flag set unexpectedly');
callback();
});
},
], done);
});
test('Disable master key', function(done) {
let account_flags = Remote.flags.account_root;
let regular_key = 'rGLnRYhy5fQK5pxZuMxtsJKrbu5onBpRst';
async.series(
[
function(callback) {
testutils.create_accounts($.remote, 'root', '1000.0', ['alice'], callback);
},
function(callback) {
let tx = $.remote.createTransaction('SetRegularKey', {
account: 'alice',
regular_key: regular_key
});
testutils.submit_transaction(tx, callback);
},
function(callback) {
$.remote.requestAccountInfo({account: 'alice'}, function(err, info) {
assert.ifError(err);
assert.strictEqual(info.account_data.RegularKey, regular_key);
callback();
});
},
function(callback) {
let tx = $.remote.createTransaction('AccountSet', {
account: 'alice',
set_flag: 'asfDisableMaster'
});
testutils.submit_transaction(tx, callback);
},
function(callback) {
let tx = $.remote.createTransaction('AccountSet', {
account: 'alice'
});
testutils.submit_transaction(tx, function(err) {
assert(err);
assert.strictEqual(err.result, 'tejMaxLedger');
assert.strictEqual(tx.summary().result.engine_result, 'tefMASTER_DISABLED');
callback();
});
}
], done);
});
});