Skip to content

Commit

Permalink
fix test case that is broken by #29 sequence requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
swswsw committed Sep 15, 2018
1 parent 7cfca42 commit 8b1ce6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
21 changes: 18 additions & 3 deletions test/testSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ let { post, get } = require('axios');
let secp = require('secp256k1');
let { sha256, addressHash } = require('../common.js');
let getSigHash = require('../sigHash.js');
let test = require('tape');

//let priv = sha256('463852363a38c0105fc1169995696fb484ec11710ba174b3994c50baa5159423'); // sample private key
let priv = Buffer.from("463852363a38c0105fc1169995696fb484ec11710ba174b3994c50baa5159423", "hex"); // bob's private key
let pub = secp.publicKeyCreate(priv); // create public key
console.log(addressHash(pub)); // create address
let addr = addressHash(pub);
console.log("addr: ", addr); // create address

let toAddr = "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj";

async function main () {

let state = (await get('http://localhost:3000/state')).data;
console.log("state: ", state);
let sequence = state.seq[addr];
if (typeof sequence === "undefined") {
sequence = 0;
}
console.log("sequence: ", sequence);

let tx = {
type: "send",
from: {
amount: 10,
pubkey: pub,
sequence: 0
sequence: sequence,
},
to: {
address: toAddr,
Expand All @@ -41,6 +52,10 @@ async function main () {
let res = await post('http://localhost:3000/txs', tx);
console.log("tx resp", res.data);


test("tx valid", function(t){
t.notEqual(res.data.result.height, 0, "response is valid");
t.end();
});

}
main()
24 changes: 20 additions & 4 deletions test/testVerifySig.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
/**
* a sample client
*/
let { post } = require('axios');
let { post, get } = require('axios');
let secp = require('secp256k1');
let { sha256, addressHash } = require('../common.js');
let getSigHash = require('../sigHash.js');
let test = require('tape');

//let priv = sha256('463852363a38c0105fc1169995696fb484ec11710ba174b3994c50baa5159423'); // sample private key
let priv = Buffer.from("463852363a38c0105fc1169995696fb484ec11710ba174b3994c50baa5159423", "hex"); // bob's private key
let pub = secp.publicKeyCreate(priv); // create public key
console.log(addressHash(pub)); // create address
let addr = addressHash(pub);
console.log("addr: ", addr); // create address

async function main () {

let state = (await get('http://localhost:3000/state')).data;
console.log("state: ", state);
let sequence = state.seq[addr];
if (typeof sequence === "undefined") {
sequence = 0;
}
console.log("sequence: ", sequence);

let tx = {
type: "verifySig",
from: {
pubkey: pub,
sequence: 0
sequence: sequence,
},
test: "test", // this is not needed. just showing that adding new property will still allow signature to be verified
to: {
Expand All @@ -35,9 +46,14 @@ async function main () {
let sigHex = signature.toString('hex');
console.log("signature hex: ", sigHex);


let res = await post('http://localhost:3000/txs', tx);
console.log("tx resp", res.data);


test("tx valid", function(t){
t.notEqual(res.data.result.height, 0, "response is valid");
t.end();
});

// verify signature
if (!secp.verify(sigHash, signature, pub)) {
Expand Down

0 comments on commit 8b1ce6f

Please sign in to comment.