Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
caedesvvv committed Oct 16, 2014
1 parent 73b7707 commit 81f299e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 83 deletions.
12 changes: 6 additions & 6 deletions test/unit/backend/services/mixerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ define(['testUtils', 'bitcoinjs-lib', 'model/wallet', 'util/coinjoin', 'model/tx

// 0. Initiator blueprint
var txInitiator = new Bitcoin.Transaction();
txInitiator.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7:0"); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
txInitiator.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7", 0); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
txInitiator.addOutput("13i6nM6iauwi3H4cDk77Nu4NY5Y1bKk3Wd", 99000000);
var txInitiatorHex = txInitiator.serializeHex();
var txInitiatorHex = txInitiator.toHex();

CoinJoin.prototype.shuffleArray = function(array) {return array};


// 1. Guest blueprint and inital tx
var txGuest = new Bitcoin.Transaction();
txGuest.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b:0"); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuest.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b", 0); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuest.addOutput("1PPFJZx5TWRwwVkLd3kpuALPfU5u2coybh", 99000000);
var txGuestHex = txGuest.serializeHex();
var txGuestHex = txGuest.toHex();
var txFullfilledHex = '01000000024b29c7abd143582985ab746905cd79731fbe953b93413dcc486f0409b9ce62890000000000ffffffffc7052b97e8d78df0ec6cc17f96e645360835c9a1105963ef726fd879cc8271210000000000ffffffff02c09ee605000000001976a914f587db9cc12fb50bd877475d73a62a8059e7054388acc09ee605000000001976a9141db621e7447d279d4267f0517e58330d0f89e53d88ac00000000';


Expand Down Expand Up @@ -162,7 +162,7 @@ define(['testUtils', 'bitcoinjs-lib', 'model/wallet', 'util/coinjoin', 'model/tx


it('starts mixing because a there is a pending task', function() {
tasks = [{state: 'paired'}, {state: 'announce', start: 300}];
tasks = [{state: 'paired'}, {state: 'announce', start: 300, tx: txFullfilledHex}];
var mixer = new MixerClass(core);
expect(mixer.name).toEqual('mixer');
expect(mixer.channel.callbacks[0][0]).toEqual('CoinJoinOpen');
Expand All @@ -175,7 +175,7 @@ define(['testUtils', 'bitcoinjs-lib', 'model/wallet', 'util/coinjoin', 'model/tx
expect(Object.keys(mixer.ongoing).length).toBe(1);

expect(core.service.wallet.fallbacks[0][0]).toBe('mixer')
expect(core.service.wallet.fallbacks[0][1]).toEqual({ state : 'announce', start : 300, timeout : 60 })
expect(core.service.wallet.fallbacks[0][1]).toEqual({ state : 'announce', start : 300, timeout : 60, tx: txFullfilledHex })
});

it('host starts announcing', function() {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/model/txSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ define(['model/wallet', 'model/tx', 'bitcoinjs-lib'], function(Wallet, Transacti
expect(tx2.change).toBe(tx.change);
expect(tx2.myamount).toBe(tx.myamount);
expect(tx2.tx.version).toBe(tx.tx.version);
expect(tx2.tx.ins[0].outpoint.hash).toBe(tx.tx.ins[0].outpoint.hash);
expect(tx2.tx.ins[0].outpoint.index).toBe(tx.tx.ins[0].outpoint.index);
expect(tx2.tx.ins[0].hash.toString('hex')).toBe(tx.tx.ins[0].hash.toString('hex'));
expect(tx2.tx.ins[0].index).toBe(tx.tx.ins[0].index);
expect(tx2.utxo[0].address).toBe(tx.utxo[0].address);
expect(tx2.utxo[0].value).toBe(tx.utxo[0].value);
};
Expand All @@ -152,8 +152,8 @@ define(['model/wallet', 'model/tx', 'bitcoinjs-lib'], function(Wallet, Transacti
expect(tx.change).toBe(2790000);
expect(tx.myamount).toBe(3000000);
expect(tx.tx.version).toBe(1);
expect(tx.tx.ins[0].outpoint.hash).toBe('64a286efcfa61bd467b721fd3ae4bb566504c328bb7d7762898de966da49dea6');
expect(tx.tx.ins[0].outpoint.index).toBe('1');
expect(Bitcoin.bufferutils.reverse(tx.tx.ins[0].hash).toString('hex')).toBe('64a286efcfa61bd467b721fd3ae4bb566504c328bb7d7762898de966da49dea6');
expect(tx.tx.ins[0].index).toBe(1);
expect(tx.utxo[0].address).toBe('1NmG1PMcwkz9UGpfu3Aa1hsGyKCApTjPvJ');
expect(tx.utxo[0].value).toBe(3000000);

Expand Down Expand Up @@ -244,8 +244,8 @@ define(['model/wallet', 'model/tx', 'bitcoinjs-lib'], function(Wallet, Transacti
expect(tx6.change).toBe(0);
expect(tx6.myamount).toBe(5000000);
expect(tx6.tx.version).toBe(1);
expect(tx6.tx.ins[0].outpoint.hash).toBe('c137710d91140ebaca2ca0f6e1608325c5dbf8ecef13dd50bacccb365a7d155c');
expect(tx6.tx.ins[0].outpoint.index).toBe('0');
expect(Bitcoin.bufferutils.reverse(tx6.tx.ins[0].hash).toString('hex')).toBe('c137710d91140ebaca2ca0f6e1608325c5dbf8ecef13dd50bacccb365a7d155c');
expect(tx6.tx.ins[0].index).toBe(0);
expect(tx6.utxo[0].address).toBe('1ptDzNsRy3CtGm8bGEfqx58PfGERmXCgs');
expect(tx6.utxo[0].value).toBe(5000000);

Expand Down
17 changes: 8 additions & 9 deletions test/unit/model/walletSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,12 @@ define(['model/wallet', 'bitcoinjs-lib'], function(Wallet, Bitcoin) {

it('gets private key', function() {
wallet.getPrivateKey([0,1], 'p4ssw0rd', function(priv) {
expect(priv.priv[0]).toEqual(55140896);
expect(priv.priv[4]).toEqual(50599429);
expect(priv.priv[10]).toEqual(0);
expect(priv.priv['t']).toEqual(10);
expect(priv.priv['s']).toEqual(0);
expect(priv.compressed).toBe(true);
expect(priv.version).toBe(0);
expect(priv.d[0]).toEqual(55140896);
expect(priv.d[4]).toEqual(50599429);
expect(priv.d[10]).toEqual(0);
expect(priv.d['t']).toEqual(10);
expect(priv.d['s']).toEqual(0);
expect(priv.pub.compressed).toBe(true);
});
});

Expand All @@ -289,11 +288,11 @@ define(['model/wallet', 'bitcoinjs-lib'], function(Wallet, Bitcoin) {
});

it('gets a stealth private key', function() {
var masterKey = Bitcoin.HDWallet.fromBase58(wallet.getPocketPrivate(0, 'p4ssw0rd'));
var masterKey = Bitcoin.HDNode.fromBase58(wallet.getPocketPrivate(0, 'p4ssw0rd'));

var ephemKey = [2, 41, 140, 192, 149, 205, 83, 114, 37, 106, 0, 164, 123, 46, 88, 38, 11, 252, 215, 149, 236, 188, 150, 165, 89, 64, 40, 218, 206, 26, 13, 49, 27];
var stealth = wallet.deriveStealthPrivateKey([0, 's'].concat(ephemKey), masterKey, {privKeys: {}});
expect(stealth.getAddress().toString()).toEqual("1GLYQWVd2Awgz4CkQC7jkenJue3nx2zLtU");
expect(stealth.pub.getAddress().toString()).toEqual("1GLYQWVd2Awgz4CkQC7jkenJue3nx2zLtU");
});

it('stores private key', function() {
Expand Down
15 changes: 0 additions & 15 deletions test/unit/util/btcSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ define(['util/btc'], function(BtcUtils) {
expect(BtcUtils.blockDiff).toEqual(562.6862479167088);
});

it('Fixes tx versions', function() {
var tx = {outs: [{address: {version: 0}}, {address: {version: 5}}]};
var identity = {wallet: {network: 'testnet', versions: {'address': 1, 'p2sh': 2}}};
var fixed = BtcUtils.fixTxVersions(tx, identity);
expect(fixed).toEqual({outs: [{address: {version: 1}}, {address: {version: 2}}]});
});

it('Does not fix versions', function() {
var tx = {outs: [{address: {version: 0}}, {address: {version: 5}}]};
var identity = {wallet: {network: 'bitcoin', versions: {'address': 1, 'p2sh': 2}}};
var fixed = BtcUtils.fixTxVersions(tx, identity);
expect(fixed).toEqual({outs: [{address: {version: 0}}, {address: {version: 5}}]});
});


it('Decodes a block header', function() {
var headerHex = "02000000d8aaf32c2bd344a921245b1e675381a5ccfccc397d68614300000000000000008c0e88fa16e068f881ad613f764e03018873e51a5e52c0db432b461365b7d77f4e565b538c9d001985c7aa6e";
var header = BtcUtils.decodeBlockHeader(headerHex);
Expand Down
30 changes: 15 additions & 15 deletions test/unit/util/coinjoinSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,46 @@ define(['util/coinjoin', 'util/protocol', 'bitcoinjs-lib'], function(CoinJoin, P

// 0. Initiator blueprint
var txInitiator = new Bitcoin.Transaction();
txInitiator.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7:0"); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
txInitiator.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7", 0); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
txInitiator.addOutput("13i6nM6iauwi3H4cDk77Nu4NY5Y1bKk3Wd", 99000000);

// 1. Guest blueprint and inital tx
var txGuest = new Bitcoin.Transaction();
txGuest.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b:0"); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuest.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b", 0); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuest.addOutput("1PPFJZx5TWRwwVkLd3kpuALPfU5u2coybh", 99000000);

// 1. Guest blueprint, bad output
var txGuestBad = new Bitcoin.Transaction();
txGuestBad.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b:0"); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuestBad.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b", 0); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
txGuestBad.addOutput("1PPFJZx5TWRwwVkLd3kpuALPfU5u2coybh", 49000000);


// 2. Initiator accepting, bad
var tx2bad = new Bitcoin.Transaction();
tx2bad.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7:0"); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
tx2bad.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7", 0); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
tx2bad.addOutput("13i6nM6iauwi3H4cDk77Nu4NY5Y1bKk3Wd", 99000000);
tx2bad.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b:0"); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
tx2bad.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b", 0); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
tx2bad.addOutput("13i6nM6iauwi3H4cDk77Nu4NY5Y1bKk3Wd", 99000000);

// 2. Initiator accepting, good
var tx2 = new Bitcoin.Transaction();
tx2.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7:0"); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
tx2.addInput("217182cc79d86f72ef635910a1c935083645e6967fc16cecf08dd7e8972b05c7", 0); // 1 BTC 1Fufjpf9RM2aQsGedhSpbSCGRHrmLMJ7yY
tx2.addOutput("13i6nM6iauwi3H4cDk77Nu4NY5Y1bKk3Wd", 99000000);
tx2.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b:0"); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
tx2.addInput("8962ceb909046f48cc3d41933b95be1f7379cd056974ab85295843d1abc7294b", 0); // 1 BTC 19TVp7iN6FjSQJTA6DNS9nfauR6PM3Mb8N
tx2.addOutput("1PPFJZx5TWRwwVkLd3kpuALPfU5u2coybh", 99000000);

// 1.
var msg1 = Protocol.CoinJoinMsg(joinId, txGuest.serializeHex());
var msg1bad = Protocol.CoinJoinMsg(joinId, txGuestBad.serializeHex());
var msg1 = Protocol.CoinJoinMsg(joinId, txGuest.toHex());
var msg1bad = Protocol.CoinJoinMsg(joinId, txGuestBad.toHex());
// 2.
var msg2 = Protocol.CoinJoinMsg(joinId, tx2.serializeHex());
var msg2bad = Protocol.CoinJoinMsg(joinId, tx2bad.serializeHex());
var msg2 = Protocol.CoinJoinMsg(joinId, tx2.toHex());
var msg2bad = Protocol.CoinJoinMsg(joinId, tx2bad.toHex());
// 3. TODO
var msg3 = Protocol.CoinJoinMsg(joinId, tx2.serializeHex());
var msg3bad = Protocol.CoinJoinMsg(joinId, tx2bad.serializeHex());
var msg3 = Protocol.CoinJoinMsg(joinId, tx2.toHex());
var msg3bad = Protocol.CoinJoinMsg(joinId, tx2bad.toHex());
// 4. TODO
var msg4 = Protocol.CoinJoinMsg(joinId, tx2.serializeHex());
var msg4bad = Protocol.CoinJoinMsg(joinId, tx2bad.serializeHex());
var msg4 = Protocol.CoinJoinMsg(joinId, tx2.toHex());
var msg4bad = Protocol.CoinJoinMsg(joinId, tx2bad.toHex());

describe('CoinJoin library', function() {

Expand Down
10 changes: 5 additions & 5 deletions test/unit/util/encryptionSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

define(['util/encryption', 'bitcoinjs-lib'], function (Encryption, Bitcoin) {
define(['util/encryption', 'bitcoinjs-lib', 'crypto-js'], function (Encryption, Bitcoin, CryptoJS) {

var convert = Bitcoin.convert;
var priv1 = [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8];
Expand All @@ -23,8 +23,8 @@ define(['util/encryption', 'bitcoinjs-lib'], function (Encryption, Bitcoin) {
});

it('encrypts', function() {
var ivWords = Bitcoin.CryptoJS.lib.WordArray.create([964042148, 1339623129, -848535864]);
var saltWords = Bitcoin.CryptoJS.lib.WordArray.create([1257186216, 1232830679, 1170146244, -885338222]);
var ivWords = CryptoJS.lib.WordArray.create([964042148, 1339623129, -848535864]);
var saltWords = CryptoJS.lib.WordArray.create([1257186216, 1232830679, 1170146244, -885338222]);
var cipher = Encryption.encrypt('foo', 'hello', ivWords, saltWords);

expect(cipher.iv).toBe("OXYdpE/ZBtnNbF7I")
Expand Down Expand Up @@ -103,8 +103,8 @@ define(['util/encryption', 'bitcoinjs-lib'], function (Encryption, Bitcoin) {
var privKey, pubKey, stealthCypher;

beforeEach(function() {
privKey = new Bitcoin.ECKey(priv1, true);
pubKey = privKey.getPub().toBytes();
privKey = Bitcoin.ECKey.fromBytes(priv1, true);
pubKey = privKey.pub.toBytes();
});

it('stealth encrypts and decrypts', function() {
Expand Down
56 changes: 29 additions & 27 deletions test/unit/util/stealthSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {

var bufToArray = function(obj) {return Array.prototype.slice.call(obj, 0);};

// Data for the test
var ephemKeyBytes = [95, 112, 167, 123, 50, 38, 10, 122, 50, 198, 34, 66, 56, 31, 186, 44, 244, 12, 14, 32, 158, 102, 90, 121, 89, 65, 142, 174, 79, 45, 162, 43, 1];
var scanKeyBytes = [250, 99, 82, 30, 51, 62, 75, 159, 106, 152, 161, 66, 104, 13, 58, 239, 77, 142, 127, 121, 114, 60, 224, 4, 54, 145, 219, 85, 195, 107, 217, 5];
var spendKeyBytes = [220, 193, 37, 11, 81, 192, 240, 58, 228, 233, 120, 224, 37, 110, 222, 81, 220, 17, 68, 227, 69, 201, 38, 38, 43, 151, 23, 177, 188, 201, 189, 27];

var ephemKey = new Bitcoin.ECKey(ephemKeyBytes, true);
var scanKey = new Bitcoin.ECKey(scanKeyBytes, true);
var spendKey = new Bitcoin.ECKey(spendKeyBytes, true);
var ephemKey = Bitcoin.ECKey.fromBytes(ephemKeyBytes, true);
var scanKey = Bitcoin.ECKey.fromBytes(scanKeyBytes, true);
var spendKey = Bitcoin.ECKey.fromBytes(spendKeyBytes, true);

var ephemKeyPubBytes = ephemKey.getPub().toBytes();
var scanKeyPubBytes = scanKey.getPub().toBytes();
var spendKeyPubBytes = spendKey.getPub().toBytes();
var ephemKeyPubBytes = ephemKey.pub.toBytes();
var scanKeyPubBytes = scanKey.pub.toBytes();
var spendKeyPubBytes = spendKey.pub.toBytes();

// Address created from the above keys
var testAddress = "vJmxHgVSxtBcoe9JQTz9qKN8ZnKcehm37FWwSfejU4AeBuxB8sX6hVPCh2iUJsAdVpbgRdUd3CUPzUCgDmLne6tccTL379SLKv15iK";
Expand All @@ -29,8 +31,8 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
});

it('performs curvedh and stealth formatting', function() {
var e = scanKey.priv;
var decKey = spendKey.getPub();
var e = scanKey.d;
var decKey = spendKey.pub;
Stealth.stealthDH(e, decKey);
});

Expand Down Expand Up @@ -60,7 +62,7 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
var address = res[0];
var ephemKey = res[1];

expect(ephemKey).toEqual(ephemKeyPubBytes)
expect(bufToArray(ephemKey)).toEqual(ephemKeyPubBytes)
expect(address.toString()).toEqual("1Gvq8pSTRocNLDyf858o4PL3yhZm5qQDgB")

// try with no ephemKeyBytes so it will be generated (normal case)
Expand All @@ -69,9 +71,9 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
});

it('uncovers the stealth secret', function() {
var secret = [75,73,116,38,110,230,200,190,217,239,242,205,16,135,187,193,16,31,23,186,217,195,120,20,248,86,27,103,245,80,197,68];
var secret = "34053245118207293422371795779243906008263774607703744573712190846512548332868";
var c = Stealth.uncoverStealth(scanKeyBytes, ephemKeyPubBytes);
expect(c).toEqual(secret);
expect(c.toString()).toEqual(secret.toString());
});

it('generates an address for receiving for a spend key with the given ephemkey', function() {
Expand All @@ -80,33 +82,33 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
var spendBytes = spendKeyPubBytes;
var keyBytes = Stealth.uncoverPublic(scanSecret, ephemBytes, spendBytes);

expect(keyBytes).toEqual([3, 5, 246, 185, 154, 68, 162, 189, 236, 139, 72, 79, 252, 238, 86, 28, 249, 160, 195, 183, 234, 146, 234, 142, 99, 52, 230, 251, 196, 241, 193, 120, 153]);
expect(Array.prototype.slice.call(keyBytes, 0)).toEqual([3, 5, 246, 185, 154, 68, 162, 189, 236, 139, 72, 79, 252, 238, 86, 28, 249, 160, 195, 183, 234, 146, 234, 142, 99, 52, 230, 251, 196, 241, 193, 120, 153]);

var keyHash = Bitcoin.crypto.hash160(keyBytes);
var address = new Bitcoin.Address(keyHash);
var address = new Bitcoin.Address(keyHash, Bitcoin.networks.bitcoin.pubKeyHash);

expect(address.toString()).toBe("1Gvq8pSTRocNLDyf858o4PL3yhZm5qQDgB");
});

it('derives a private key from spend key and shared secret', function() {
var privKey = Stealth.uncoverPrivate(scanKeyBytes, ephemKeyPubBytes, spendKeyBytes);
var keyBytes = privKey.getPub().toBytes();
var keyBytes = privKey.pub.toBytes();

var keyHash = Bitcoin.crypto.hash160(keyBytes);
var address = new Bitcoin.Address(keyHash);
var keyHash = Bitcoin.crypto.hash160(new Bitcoin.Buffer(keyBytes));
var address = new Bitcoin.Address(keyHash, Bitcoin.networks.bitcoin.pubKeyHash);
expect(address.toString()).toBe("1Gvq8pSTRocNLDyf858o4PL3yhZm5qQDgB");
});

it('derives public key from spend key and shared secret', function() {
var spendKey = new Bitcoin.ECPubKey(spendKeyPubBytes);
var spendKey = Bitcoin.ECPubKey.fromBytes(spendKeyPubBytes);
var c = new Bitcoin.BigInteger("10000");
var keyBytes = Stealth.derivePublicKey(spendKey, c);

expect(keyBytes).toEqual([3, 173, 36, 66, 71, 110, 69, 203, 135, 107, 57, 44, 117, 28, 232, 195, 123, 20, 36, 239, 18, 50, 107, 196, 154, 84, 37, 176, 43, 123, 246, 179, 204]);
expect(bufToArray(keyBytes)).toEqual([3, 173, 36, 66, 71, 110, 69, 203, 135, 107, 57, 44, 117, 28, 232, 195, 123, 20, 36, 239, 18, 50, 107, 196, 154, 84, 37, 176, 43, 123, 246, 179, 204]);
});

it('derives a bitcoin address from spendkey and shared secret', function() {
var spendKey = new Bitcoin.ECPubKey(spendKeyPubBytes);
var spendKey = Bitcoin.ECPubKey.fromBytes(spendKeyPubBytes);
var c = new Bitcoin.BigInteger("1000");
var address = Stealth.deriveAddress(spendKey, c);

Expand All @@ -116,14 +118,14 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
it('builds the stealth nonce output', function() {
var nonce = 20;
var ephemBytes = ephemKeyPubBytes;
var stealthOut = Stealth.buildNonceOutput(ephemBytes, nonce)
var script = Stealth.buildNonceScript(ephemBytes, nonce)

expect(stealthOut.value).toBe(0);
expect(stealthOut.script.buffer.length).toBe(2+1+4+33);
expect(stealthOut.script.buffer[2]).toBe(Stealth.nonceVersion);
//expect(stealthOut.value).toBe(0);
expect(script.buffer.length).toBe(2+1+4+33);
expect(script.buffer[2]).toBe(Stealth.nonceVersion);
// TODO: is this correct or should be [0,0,0,20]?
expect(stealthOut.script.buffer.slice(3,7)).toEqual([20,0,0,0]);
expect(stealthOut.script.buffer.slice(7,40)).toEqual(ephemBytes);
expect(bufToArray(script.buffer.slice(3,7))).toEqual([20,0,0,0]);
expect(bufToArray(script.buffer.slice(7,40))).toEqual(ephemBytes);
});

it('checks prefix against the given array', function() {
Expand Down Expand Up @@ -167,9 +169,9 @@ define(['util/stealth', 'bitcoinjs-lib'], function(Stealth, Bitcoin) {
expect(recipient.address.toString()).toBe("1Gvq8pSTRocNLDyf858o4PL3yhZm5qQDgB");
expect(newTx.outs.length).toBe(1);
var outBuffer = newTx.outs[0].script.chunks[1];
expect(newTx.outs[0].script.chunks[0]).toBe(Bitcoin.Opcode.map.OP_RETURN); // OP_RETURN
expect(newTx.outs[0].script.chunks[0]).toBe(Bitcoin.opcodes.OP_RETURN); // OP_RETURN
expect(outBuffer[0]).toBe(Stealth.nonceVersion);
expect(outBuffer.slice(1,5)).toEqual([1,0,0,0]);
expect(Array.prototype.slice.call(outBuffer, 1, 5)).toEqual([1,0,0,0]);
expect(newTx.outs[0].script.buffer)
});
});
Expand Down

0 comments on commit 81f299e

Please sign in to comment.