@bitpay-labs/bitcore-wallet-service 11.7.0 → 11.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/lib/server.ts +5 -0
- package/test/integration/server.test.ts +127 -0
- package/ts_build/package.json +4 -4
- package/ts_build/src/lib/server.d.ts.map +1 -1
- package/ts_build/src/lib/server.js +3 -0
- package/ts_build/src/lib/server.js.map +1 -1
- package/ts_build/test/integration/server.test.js +110 -0
- package/ts_build/test/integration/server.test.js.map +1 -1
|
@@ -7555,6 +7555,116 @@ describe('Wallet service', function () {
|
|
|
7555
7555
|
result.nonce.should.equal(5);
|
|
7556
7556
|
});
|
|
7557
7557
|
});
|
|
7558
|
+
describe('#signTx nonce override', function () {
|
|
7559
|
+
const ETH_ADDR = '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A';
|
|
7560
|
+
let server, wallet, fromAddr;
|
|
7561
|
+
beforeEach(async function () {
|
|
7562
|
+
({ server, wallet } = await helpers_1.default.createAndJoinWallet(1, 1, { coin: 'eth' }));
|
|
7563
|
+
const address = await util_1.default.promisify(server.createAddress).call(server, {});
|
|
7564
|
+
fromAddr = address.address;
|
|
7565
|
+
await helpers_1.default.stubUtxos(server, wallet, [1, 2], { coin: 'eth' });
|
|
7566
|
+
blockchainExplorer.getTransactionCount = sinon_1.default.stub().callsArgWith(1, null, '5');
|
|
7567
|
+
});
|
|
7568
|
+
it('should accept nonce passthrough in signTx', async function () {
|
|
7569
|
+
const txp = await helpers_1.default.createAndPublishTx(server, {
|
|
7570
|
+
outputs: [{ toAddress: ETH_ADDR, amount: 8000 }],
|
|
7571
|
+
feePerKb: 123e2,
|
|
7572
|
+
from: fromAddr
|
|
7573
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7574
|
+
txp.nonce.should.equal('5');
|
|
7575
|
+
const signatures = helpers_1.default.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
|
|
7576
|
+
const signed = await util_1.default.promisify(server.signTx).call(server, {
|
|
7577
|
+
txProposalId: txp.id,
|
|
7578
|
+
signatures,
|
|
7579
|
+
nonce: Number(txp.nonce)
|
|
7580
|
+
});
|
|
7581
|
+
signed.status.should.equal('accepted');
|
|
7582
|
+
signed.nonce.should.equal(5);
|
|
7583
|
+
});
|
|
7584
|
+
it('should accept nonce override in signTx', async function () {
|
|
7585
|
+
const txp = await helpers_1.default.createAndPublishTx(server, {
|
|
7586
|
+
outputs: [{ toAddress: ETH_ADDR, amount: 8000 }],
|
|
7587
|
+
feePerKb: 123e2,
|
|
7588
|
+
from: fromAddr
|
|
7589
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7590
|
+
txp.nonce.should.equal('5');
|
|
7591
|
+
const overrideNonce = 99;
|
|
7592
|
+
const fetched = await util_1.default.promisify(server.getTx).call(server, { txProposalId: txp.id });
|
|
7593
|
+
fetched.nonce = overrideNonce;
|
|
7594
|
+
const signatures = helpers_1.default.clientSign(fetched, TestData.copayers[0].xPrivKey_44H_0H_0H);
|
|
7595
|
+
const signed = await util_1.default.promisify(server.signTx).call(server, {
|
|
7596
|
+
txProposalId: txp.id,
|
|
7597
|
+
signatures,
|
|
7598
|
+
nonce: overrideNonce
|
|
7599
|
+
});
|
|
7600
|
+
signed.status.should.equal('accepted');
|
|
7601
|
+
signed.nonce.should.equal(overrideNonce);
|
|
7602
|
+
});
|
|
7603
|
+
it('should reject nonce override that conflicts with pending txp', async function () {
|
|
7604
|
+
const txp1 = await helpers_1.default.createAndPublishTx(server, {
|
|
7605
|
+
outputs: [{ toAddress: ETH_ADDR, amount: 1000 }],
|
|
7606
|
+
feePerKb: 123e2,
|
|
7607
|
+
from: fromAddr
|
|
7608
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7609
|
+
txp1.nonce.should.equal('5');
|
|
7610
|
+
blockchainExplorer.getTransactionCount = sinon_1.default.stub().callsArgWith(1, null, '6');
|
|
7611
|
+
const txp2 = await helpers_1.default.createAndPublishTx(server, {
|
|
7612
|
+
outputs: [{ toAddress: ETH_ADDR, amount: 2000 }],
|
|
7613
|
+
feePerKb: 123e2,
|
|
7614
|
+
from: fromAddr
|
|
7615
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7616
|
+
txp2.nonce.should.equal('6');
|
|
7617
|
+
const fetched = await util_1.default.promisify(server.getTx).call(server, { txProposalId: txp2.id });
|
|
7618
|
+
fetched.nonce = 5;
|
|
7619
|
+
const signatures = helpers_1.default.clientSign(fetched, TestData.copayers[0].xPrivKey_44H_0H_0H);
|
|
7620
|
+
try {
|
|
7621
|
+
await util_1.default.promisify(server.signTx).call(server, {
|
|
7622
|
+
txProposalId: txp2.id,
|
|
7623
|
+
signatures,
|
|
7624
|
+
nonce: 5
|
|
7625
|
+
});
|
|
7626
|
+
throw new Error('should have thrown');
|
|
7627
|
+
}
|
|
7628
|
+
catch (err) {
|
|
7629
|
+
err.code.should.equal('TX_NONCE_CONFLICT');
|
|
7630
|
+
}
|
|
7631
|
+
});
|
|
7632
|
+
it('should not crash on nonce conflict check when nonce is null', async function () {
|
|
7633
|
+
const txp = await helpers_1.default.createAndPublishTx(server, {
|
|
7634
|
+
outputs: [{ toAddress: ETH_ADDR, amount: 8000 }],
|
|
7635
|
+
feePerKb: 123e2,
|
|
7636
|
+
from: fromAddr,
|
|
7637
|
+
deferNonce: true
|
|
7638
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7639
|
+
should.not.exist(txp.nonce);
|
|
7640
|
+
const fetched = await util_1.default.promisify(server.getTx).call(server, { txProposalId: txp.id });
|
|
7641
|
+
fetched.nonce = 99;
|
|
7642
|
+
const signatures = helpers_1.default.clientSign(fetched, TestData.copayers[0].xPrivKey_44H_0H_0H);
|
|
7643
|
+
const signed = await util_1.default.promisify(server.signTx).call(server, {
|
|
7644
|
+
txProposalId: txp.id,
|
|
7645
|
+
signatures,
|
|
7646
|
+
nonce: 99
|
|
7647
|
+
});
|
|
7648
|
+
signed.status.should.equal('accepted');
|
|
7649
|
+
signed.nonce.should.equal(99);
|
|
7650
|
+
});
|
|
7651
|
+
it('should ignore nonce override for non-EVM chains', async function () {
|
|
7652
|
+
const { server: btcServer, wallet: btcWallet } = await helpers_1.default.createAndJoinWallet(1, 1);
|
|
7653
|
+
await helpers_1.default.stubUtxos(btcServer, btcWallet, [1, 2]);
|
|
7654
|
+
const txp = await helpers_1.default.createAndPublishTx(btcServer, {
|
|
7655
|
+
outputs: [{ toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', amount: 8000 }],
|
|
7656
|
+
feePerKb: 100e2,
|
|
7657
|
+
}, TestData.copayers[0].privKey_1H_0);
|
|
7658
|
+
const signatures = helpers_1.default.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
|
|
7659
|
+
const signed = await util_1.default.promisify(btcServer.signTx).call(btcServer, {
|
|
7660
|
+
txProposalId: txp.id,
|
|
7661
|
+
signatures,
|
|
7662
|
+
nonce: 99
|
|
7663
|
+
});
|
|
7664
|
+
signed.status.should.equal('accepted');
|
|
7665
|
+
should.not.exist(signed.nonce);
|
|
7666
|
+
});
|
|
7667
|
+
});
|
|
7558
7668
|
describe('#broadcastTx & #broadcastRawTx', function () {
|
|
7559
7669
|
let server;
|
|
7560
7670
|
let wallet;
|