forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote-test.js
More file actions
192 lines (156 loc) · 5.26 KB
/
remote-test.js
File metadata and controls
192 lines (156 loc) · 5.26 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
var assert = require('assert');
var Remote = require('ripple-lib').Remote;
var testutils = require('./testutils.js');
var config = testutils.init_config();
suite('Remote functions', function() {
var $ = { };
setup(function(done) {
testutils.build_setup().call($, done);
});
teardown(function(done) {
testutils.build_teardown().call($, done);
});
test('request_ledger with ledger index', function(done) {
var request = $.remote.request_ledger();
request.ledger_index(3);
request.callback(function(err, m) {
assert(!err);
assert.strictEqual(m.ledger.ledger_index, '3');
done();
});
});
test('request_ledger with ledger index string', function(done) {
var request = $.remote.request_ledger();
request.ledger_index('3');
request.callback(function(err, m) {
assert(err);
assert.strictEqual(err.error, 'remoteError');
assert.strictEqual(err.remote.error, 'invalidParams');
done();
});
});
test('request_ledger with ledger identifier', function(done) {
var request = $.remote.request_ledger();
request.ledger_index('current');
request.callback(function(err, m) {
assert(!err);
assert.strictEqual(m.ledger.ledger_index, '3');
done();
});
});
test('request_ledger_current', function(done) {
$.remote.request_ledger_current(function(err, m) {
assert(!err);
assert.strictEqual(m.ledger_current_index, 3);
done();
});
});
test('request_ledger_hash', function(done) {
$.remote.request_ledger_hash(function(err, m) {
assert(!err);
assert.strictEqual(m.ledger_index, 2);
done();
})
});
test('manual account_root success', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
//console.log('result: %s', JSON.stringify(r));
assert(!err);
assert('ledger_hash' in r, 'Result missing property "ledger_hash"');
var request = $.remote.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
request.callback(function(err, r) {
// console.log('account_root: %s', JSON.stringify(r));
assert(!err);
assert('node' in r, 'Result missing property "node"');
done();
});
});
});
test('account_root remote malformedAddress', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
// console.log('result: %s', JSON.stringify(r));
assert(!err);
var request = $.remote.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root('zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
request.callback(function(err, r) {
// console.log('account_root: %s', JSON.stringify(r));
assert(err);
assert.strictEqual(err.error, 'remoteError');
assert.strictEqual(err.remote.error, 'malformedAddress');
done();
});
})
});
test('account_root entryNotFound', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
// console.log('result: %s', JSON.stringify(r));
assert(!err);
var request = $.remote.request_ledger_entry('account_root')
.ledger_hash(r.ledger_hash)
.account_root('alice');
request.callback(function(err, r) {
// console.log('error: %s', m);
assert(err);
assert.strictEqual(err.error, 'remoteError');
assert.strictEqual(err.remote.error, 'entryNotFound');
done();
});
})
});
test('ledger_entry index', function(done) {
var self = this;
$.remote.request_ledger_hash(function(err, r) {
assert(!err);
var request = $.remote.request_ledger_entry('index')
.ledger_hash(r.ledger_hash)
.account_root('alice')
.index('2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8');
request.callback(function(err, r) {
assert(!err);
assert('node_binary' in r, 'Result missing property "node_binary"');
done();
});
})
});
test('create account', function(done) {
var self = this;
var root_id = $.remote.account('root')._account_id;
$.remote.request_subscribe().accounts(root_id).request();
$.remote.transaction()
.payment('root', 'alice', '10000.0')
.once('error', done)
.once('proposed', function(res) {
//console.log('Submitted', res);
$.remote.ledger_accept();
})
.once('success', function (r) {
//console.log('account_root: %s', JSON.stringify(r));
// Need to verify account and balance.
done();
})
.submit();
});
test('create account final', function(done) {
var self = this;
var got_proposed;
var got_success;
var root_id = $.remote.account('root')._account_id;
$.remote.request_subscribe().accounts(root_id).request();
var transaction = $.remote.transaction()
.payment('root', 'alice', '10000.0')
transaction.once('submitted', function (m) {
// console.log('proposed: %s', JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
assert.strictEqual(m.engine_result, 'tesSUCCESS');
});
transaction.submit(done);
testutils.ledger_wait($.remote, transaction);
});
});
//vim:sw=2:sts=2:ts=8:et