Skip to content

Commit 57e0914

Browse files
juscamarenapedrobranco
authored andcommitted
Update bitcoind container to 0.17 with tests updated
1 parent d8bb990 commit 57e0914

File tree

6 files changed

+86
-57
lines changed

6 files changed

+86
-57
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sut:
1313
working_dir: /app
1414

1515
bitcoin-core:
16-
image: ruimarinho/bitcoin-core:0.15-alpine
16+
image: ruimarinho/bitcoin-core:0.17-alpine
1717
command:
1818
-printtoconsole
1919
-regtest=1

test/client_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ describe('Client', () => {
8989
it('should have all the methods listed by `help`', async () => {
9090
const help = await new Client(config.bitcoin).help();
9191

92-
_.difference(parse(help), _.invokeMap(Object.keys(methods), String.prototype.toLowerCase)).should.be.empty();
92+
_.difference(_.without(parse(help), 'getaddressbyaccount'), _.invokeMap(Object.keys(methods), String.prototype.toLowerCase)).should.be.empty();
9393
});
9494

9595
it('should accept valid versions', async () => {
96-
await new Client(_.defaults({ version: '0.15.0.1' }, config.bitcoin)).getInfo();
97-
await new Client(_.defaults({ version: '0.15.0' }, config.bitcoin)).getInfo();
96+
await new Client(_.defaults({ version: '0.15.0.1' }, config.bitcoin)).getNetworkInfo();
97+
await new Client(_.defaults({ version: '0.15.0' }, config.bitcoin)).getNetworkInfo();
98+
await new Client(_.defaults({ version: '0.17.0' }, config.bitcoin)).getNetworkInfo();
9899
});
99100
});
100101

test/multi_wallet_test.js

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ describe('Multi Wallet', () => {
2222
before(async () => {
2323
const [tip] = await client.getChainTips();
2424

25-
if (tip.height >= 200) {
25+
if (tip.height >= 432) {
2626
return null;
2727
}
2828

29-
await client.generate(200);
29+
await client.generate(432);
3030
});
3131

3232
describe('node-level requests', () => {
@@ -56,6 +56,17 @@ describe('Multi Wallet', () => {
5656
});
5757

5858
describe('wallet-level requests', () => {
59+
describe('getNewAddressesWithLabel()', () => {
60+
it('should retrieve an address with a set label', async () => {
61+
await client.getNewAddress('testlabelmulti');
62+
63+
const labelList = await client.listLabels();
64+
65+
labelList.should.be.an.Array();
66+
labelList.should.containEql('testlabelmulti');
67+
});
68+
});
69+
5970
describe('getBalance()', () => {
6071
it('should return the total server\'s balance', async () => {
6172
const balance = await client.getBalance();
@@ -64,39 +75,50 @@ describe('Multi Wallet', () => {
6475
});
6576

6677
it('should support named parameters', async () => {
67-
const mainWalletBalance = await client.getBalance({ minconf: 0 });
68-
const mainWalletBalanceWithoutParameters = await client.getBalance('*', 0);
78+
const mainWalletBalance = await client.getBalance({ dummy: '*', minconf: 0 });
79+
const mainWalletBalanceWithoutNamedParameters = await client.getBalance('*', 0);
6980

70-
mainWalletBalanceWithoutParameters.should.equal(mainWalletBalance);
81+
mainWalletBalance.should.equal(mainWalletBalanceWithoutNamedParameters);
7182
});
7283
});
7384

7485
describe('getNewAddress()', () => {
7586
it('should return a new bitcoin address', async () => {
7687
const address = await client.getNewAddress('test', 'legacy');
88+
const amount = await client.getReceivedByAddress({ address, minconf: 0 });
7789

78-
const output = await client.validateAddress(address);
90+
amount.should.equal(0);
91+
});
92+
});
7993

80-
output.isvalid.should.be.true();
94+
describe('createPsbt()', () => {
95+
it('should create a Psbt', async () => {
96+
const inputs = [{ txid: '4fcfa1a5c6864c9783d9474566488cf3d0ae43087ae66618715f10a0dd7997e9', vout: 0 }];
97+
const dest = [{ mkteeBFmGkraJaWN5WzqHCjmbQWVrPo5X3: 1000 }];
98+
const pbst = await client.createPsbt(inputs, dest);
99+
100+
pbst.should.be.a.String();
81101
});
82102
});
83103

84104
describe('listTransactions()', () => {
85-
it('should return the most recent list of transactions from all accounts using specific count', async () => {
86-
const address = await client.getNewAddress('test');
105+
it('should return the most recent list of transactions using specific count', async () => {
106+
const address = await client.getNewAddress('listspecificcount');
87107

88108
// Generate 5 transactions.
89109
for (let i = 0; i < 5; i++) {
90110
await client.sendToAddress(address, 0.1);
91111
}
92112

93-
const transactions = await client.listTransactions('*', 5);
113+
const transactions = await client.listTransactions({ count: 5 });
94114

95115
transactions.should.be.an.Array();
96116
transactions.should.matchEach(value => {
117+
value.label.should.equal('listspecificcount');
97118
// Only a small subset of transaction properties are being asserted here to make
98119
// sure we've received a transaction and not an empty object instead.
99120
value.should.have.keys(
121+
'label',
100122
'address',
101123
'amount',
102124
'category',
@@ -109,21 +131,24 @@ describe('Multi Wallet', () => {
109131
transactions.length.should.be.greaterThanOrEqual(5);
110132
});
111133

112-
it('should return the most recent list of transactions from all accounts using default count', async () => {
113-
const address = await client.getNewAddress('test');
134+
it('should return the most recent list of transactions using default count', async () => {
135+
const address = await client.getNewAddress('listdefaultcount');
114136

115137
// Generate 5 transactions.
116138
for (let i = 0; i < 5; i++) {
117139
await client.sendToAddress(address, 0.1);
118140
}
119141

120-
const transactions = await client.listTransactions('*');
142+
const transactions = await client.listTransactions();
121143

122144
transactions.should.be.an.Array();
123145
transactions.should.matchEach(value => {
146+
value.label.should.equal('listdefaultcount');
147+
124148
// Only a small subset of transaction properties are being asserted here to make
125149
// sure we've received a transaction and not an empty object instead.
126150
value.should.have.keys(
151+
'label',
127152
'address',
128153
'amount',
129154
'category',
@@ -136,27 +161,29 @@ describe('Multi Wallet', () => {
136161
});
137162

138163
it('should support named parameters', async () => {
139-
const address = await client.getNewAddress('test');
164+
const address = await client.getNewAddress('testlistwithparams');
140165

141166
// Generate 5 transactions.
142167
for (let i = 0; i < 5; i++) {
143168
await client.sendToAddress(address, 0.1);
144169
}
145170

146-
let transactions = await client.listTransactions({ account: '*' });
171+
let transactions = await client.listTransactions();
147172

148173
transactions.should.be.an.Array();
149174
transactions.length.should.be.greaterThanOrEqual(5);
150175

151176
// Make sure `count` is read correctly.
152-
transactions = await client.listTransactions({ account: '*', count: 1 });
177+
transactions = await client.listTransactions({ count: 1 });
153178

154179
transactions.should.be.an.Array();
155180
transactions.should.have.length(1);
156181
transactions.should.matchEach(value => {
182+
value.label.should.equal('testlistwithparams');
157183
// Only a small subset of transaction properties are being asserted here to make
158184
// sure we've received a transaction and not an empty object instead.
159185
value.should.have.keys(
186+
'label',
160187
'address',
161188
'amount',
162189
'category',

test/parser_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ describe('Parser', () => {
6767

6868
describe('headers', () => {
6969
it('should return the response headers if `headers` is enabled', async () => {
70-
const [info, headers] = await new Client(defaults({ headers: true }, config.bitcoin)).getInfo();
70+
const [info, headers] = await new Client(defaults({ headers: true }, config.bitcoin)).getNetworkInfo();
7171

7272
info.should.be.an.Object();
7373
headers.should.have.keys('date', 'connection', 'content-length', 'content-type');
7474
});
7575

7676
it('should return the response headers if `headers` is enabled using callbacks', done => {
77-
new Client(defaults({ headers: true }, config.bitcoin)).getInfo((err, [info, headers]) => {
77+
new Client(defaults({ headers: true }, config.bitcoin)).getNetworkInfo((err, [info, headers]) => {
7878
should.not.exist(err);
7979

8080
info.should.be.an.Object();

test/rest_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('REST', () => {
8585
it('should return a block json-encoded by default', async () => {
8686
const block = await client.getBlockByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', { extension: 'json' });
8787

88-
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
88+
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
8989
block.tx.should.matchEach(value => value.should.be.an.Object());
9090
});
9191

@@ -105,7 +105,7 @@ describe('REST', () => {
105105
it('should return a block summary json-encoded if `summary` is enabled', async () => {
106106
const block = await client.getBlockByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', { extension: 'json', summary: true });
107107

108-
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
108+
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
109109
block.tx.should.matchEach(value => value.should.be.a.String());
110110
});
111111
});
@@ -115,7 +115,7 @@ describe('REST', () => {
115115
const headers = await client.getBlockHeadersByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', 1, { extension: 'json' });
116116

117117
headers.should.have.length(1);
118-
headers[0].should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'time', 'version', 'versionHex');
118+
headers[0].should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nonce', 'time', 'version', 'versionHex');
119119
headers[0].hash.should.equal('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206');
120120
});
121121

@@ -194,7 +194,7 @@ describe('REST', () => {
194194
await client.sendToAddress(address, 0.1);
195195
}
196196

197-
const transactions = await client.listTransactions('test');
197+
const transactions = await client.listTransactions();
198198

199199
Object.keys(content).length.should.not.equal(transactions.length);
200200
});

test/single_wallet_test.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ describe('Single Wallet', () => {
2222
before(async () => {
2323
const [tip] = await client.getChainTips();
2424

25-
if (tip.height >= 200) {
25+
if (tip.height >= 432) {
2626
return null;
2727
}
2828

29-
await client.generate(200);
29+
await client.generate(432);
3030
});
3131

3232
describe('node-level requests', () => {
@@ -51,18 +51,21 @@ describe('Single Wallet', () => {
5151
const client = new Client(config.bitcoin);
5252
const wallets = await client.listWallets();
5353

54-
wallets.should.eql(['wallet.dat']);
54+
// wallet is shown as '' unless -wallet set in config
55+
wallets.should.eql(['']);
5556
});
5657
});
5758
});
5859

5960
describe('wallet-level requests', () => {
60-
describe('getAccountAddress()', () => {
61-
it('should retrieve an account address', async () => {
62-
const address = await client.getAccountAddress('test');
63-
const account = await client.getAccount(address);
64-
65-
account.should.equal('test');
61+
describe('getNewAddressesWithLabel()', () => {
62+
it('should retrieve an address with a set label', async () => {
63+
const address = await client.getNewAddress('testlabelsingle');
64+
const labelList = await client.listLabels();
65+
66+
labelList.should.be.an.Array();
67+
labelList.should.containEql('testlabelsingle');
68+
address.should.be.a.String();
6669
});
6770
});
6871

@@ -74,51 +77,47 @@ describe('Single Wallet', () => {
7477
});
7578

7679
it('should support named parameters', async () => {
77-
const client = new Client(defaults({ version: '0.15.0' }, config.bitcoin));
80+
const client = new Client(defaults({ version: '0.17.0' }, config.bitcoin));
7881

79-
const mainWalletBalance = await client.getBalance({ account: '*', minconf: 0 });
80-
const mainWalletBalanceWithoutParameters = await client.getBalance('*', 0);
81-
const testWalletBalance = await client.getBalance({ account: 'test', minconf: 0 });
82+
const mainWalletBalance = await client.getBalance({ dummy: '*', minconf: 0 });
83+
const mainWalletBalanceWithoutNamedParameters = await client.getBalance('*', 0);
8284

83-
mainWalletBalance.should.not.equal(testWalletBalance);
84-
mainWalletBalanceWithoutParameters.should.equal(mainWalletBalance);
85+
mainWalletBalance.should.equal(mainWalletBalanceWithoutNamedParameters);
8586
});
8687
});
8788

8889
describe('getNewAddress()', () => {
8990
it('should return a new bitcoin address', async () => {
90-
await client.getNewAddress('test');
91-
92-
const addresses = await client.getAddressesByAccount('test');
91+
const address = await client.getNewAddress('test');
9392

94-
addresses.length.should.be.above(1);
93+
address.should.be.a.String();
9594
});
9695
});
9796

9897
describe('listTransactions()', () => {
99-
it('should return the most recent list of transactions from all accounts using specific count', async () => {
100-
const address = await client.getNewAddress('test');
98+
it('should return the most recent list of transactions using specific count', async () => {
99+
const address = await client.getNewAddress('listspecificcount');
101100

102101
// Generate 5 transactions.
103102
for (let i = 0; i < 5; i++) {
104103
await client.sendToAddress(address, 0.1);
105104
}
106105

107-
const transactions = await client.listTransactions('test', 5);
106+
const transactions = await client.listTransactions('*', 5);
108107

109108
transactions.should.be.an.Array();
110109
transactions.length.should.be.greaterThanOrEqual(5);
111110
});
112111

113-
it('should return the most recent list of transactions from all accounts using default count', async () => {
114-
const transactions = await client.listTransactions('test');
112+
it('should return the most recent list of transactions using default count', async () => {
113+
const transactions = await client.listTransactions();
115114

116115
transactions.should.be.an.Array();
117116
transactions.should.matchEach(value => {
118117
// Only a small subset of transaction properties are being asserted here to make
119118
// sure we've received a transaction and not an empty object instead.
120119
value.should.have.keys(
121-
'account',
120+
'label',
122121
'address',
123122
'amount',
124123
'category',
@@ -131,20 +130,20 @@ describe('Single Wallet', () => {
131130
});
132131

133132
it('should support named parameters', async () => {
134-
const address = await client.getNewAddress('test');
133+
const address = await client.getNewAddress('testlistwithparams');
135134

136135
// Generate 5 transactions.
137136
for (let i = 0; i < 5; i++) {
138137
await client.sendToAddress(address, 0.1);
139138
}
140139

141-
let transactions = await new Client(defaults({ version: '0.15.0' }, config.bitcoin)).listTransactions({ account: 'test' });
140+
let transactions = await new Client(defaults({ version: '0.17.0' }, config.bitcoin)).listTransactions();
142141

143142
transactions.should.be.an.Array();
144143
transactions.length.should.be.greaterThanOrEqual(5);
145144

146145
// Make sure `count` is read correctly.
147-
transactions = await new Client(defaults({ version: '0.15.0' }, config.bitcoin)).listTransactions({ account: 'test', count: 1 });
146+
transactions = await new Client(defaults({ version: '0.17.0' }, config.bitcoin)).listTransactions({ count: 1 });
148147

149148
transactions.should.be.an.Array();
150149
transactions.should.have.length(1);
@@ -161,15 +160,17 @@ describe('Single Wallet', () => {
161160
];
162161
const response = await client.command(batch);
163162

164-
response.should.eql([['wallet.dat'], ['wallet.dat'], ['wallet.dat']]);
163+
// 0.17 for some reason has wallets shown as ''
164+
// I'm guessing if you load a wallet specifically it will show it
165+
response.should.eql([[''], [''], ['']]);
165166
});
166167

167168
it('should support request parameters in batched requests', async () => {
168169
const batch = [{ method: 'getnewaddress' }, { method: 'validateaddress', parameters: ['mkteeBFmGkraJaWN5WzqHCjmbQWVrPo5X3'] }];
169170

170171
const [newAddress, addressValidation] = await client.command(batch);
171172

172-
addressValidation.should.have.properties('address', 'ismine', 'isvalid', 'scriptPubKey');
173+
addressValidation.should.have.properties('address', 'isvalid', 'scriptPubKey', 'isscript', 'iswitness');
173174
newAddress.should.be.a.String();
174175
});
175176

@@ -178,7 +179,7 @@ describe('Single Wallet', () => {
178179

179180
const [validateAddressError, validateAddress] = await client.command(batch);
180181

181-
validateAddress.should.have.properties('address', 'ismine', 'isvalid', 'scriptPubKey');
182+
validateAddress.should.have.properties('address', 'isvalid', 'scriptPubKey');
182183
validateAddressError.should.be.an.instanceOf(RpcError);
183184
validateAddressError.code.should.equal(-1);
184185
});

0 commit comments

Comments
 (0)