Various fixes.

This commit is contained in:
Gav Wood 2014-01-20 14:53:02 +00:00
parent 6eafb9e6f8
commit a08ce2bde1
4 changed files with 32 additions and 20 deletions

View File

@ -17,3 +17,5 @@ target_link_libraries(testeth ethereum)
target_link_libraries(testeth cryptopp) target_link_libraries(testeth cryptopp)
target_link_libraries(testeth secp256k1) target_link_libraries(testeth secp256k1)
target_link_libraries(testeth gmp) target_link_libraries(testeth gmp)
target_link_libraries(testeth boost_system)
target_link_libraries(testeth boost_filesystem)

View File

@ -34,8 +34,16 @@ int cryptoTest()
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d"); bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
cout << "TX: " << RLP(tx) << endl; cout << "TX: " << RLP(tx) << endl;
Transaction t(tx); Transaction t2(tx);
cout << "SENDER: " << hex << t.sender() << endl; cout << "SENDER: " << hex << t2.sender() << endl;
secp256k1_start();
Transaction t;
t.nonce = 0;
t.fee = 0;
t.value = 1; // 1 wei.
t.receiveAddress = toAddress(sha3("123"));
bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s); bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s);
cout << "SIG: " << sig64.size() << " " << asHex(sig64) << " " << t.vrs.v << endl; cout << "SIG: " << sig64.size() << " " << asHex(sig64) << " " << t.vrs.v << endl;
@ -48,8 +56,6 @@ int cryptoTest()
bytes privkey = sha3Bytes("123"); bytes privkey = sha3Bytes("123");
secp256k1_start();
{ {
bytes pubkey(65); bytes pubkey(65);
int pubkeylen = 65; int pubkeylen = 65;
@ -68,6 +74,9 @@ int cryptoTest()
bytes sig(64); bytes sig(64);
u256 nonce = 0; u256 nonce = 0;
int v = 0; int v = 0;
cout << asHex(hmsg) << endl;
cout << asHex(privkey) << endl;
cout << hex << nonce << endl;
int ret = secp256k1_ecdsa_sign_compact((byte const*)hmsg.data(), hmsg.size(), sig.data(), privkey.data(), (byte const*)&nonce, &v); int ret = secp256k1_ecdsa_sign_compact((byte const*)hmsg.data(), hmsg.size(), sig.data(), privkey.data(), (byte const*)&nonce, &v);
cout << "MYSIG: " << dec << ret << " " << sig.size() << " " << asHex(sig) << " " << v << endl; cout << "MYSIG: " << dec << ret << " " << sig.size() << " " << asHex(sig) << " " << v << endl;

View File

@ -35,7 +35,7 @@ int main()
rlpTest(); rlpTest();
trieTest(); trieTest();
// daggerTest(); // daggerTest();
// cryptoTest(); cryptoTest();
stateTest(); stateTest();
return 0; return 0;
} }

View File

@ -20,43 +20,44 @@
* State test functions. * State test functions.
*/ */
#include <secp256k1.h>
#include <BlockChain.h>
#include <State.h> #include <State.h>
using namespace std; using namespace std;
using namespace eth; using namespace eth;
struct KeyPair
{
KeyPair() {}
KeyPair(PrivateKey _k): priv(_k), addr(toPublic(_k)) {}
PrivateKey priv;
Address addr;
};
int stateTest() int stateTest()
{ {
KeyPair me = sha3("Gav Wood"); KeyPair me = sha3("Gav Wood");
KeyPair myMiner = sha3("Gav's Miner"); KeyPair myMiner = sha3("Gav's Miner");
// KeyPair you = sha3("123"); // KeyPair you = sha3("123");
State s(myMiner.addr); BlockChain bc("/tmp");
State s(myMiner.address(), "/tmp");
// Mine to get some ether! // Mine to get some ether!
s.mine(); s.commitToMine(bc);
while (!s.mine(100)) {}
bc.attemptImport(s.blockData());
s.sync(bc);
bytes tx; bytes tx;
{ {
Transaction t; Transaction t;
t.nonce = s.transactionsFrom(myMiner.addr); t.nonce = s.transactionsFrom(myMiner.address());
t.fee = 0; t.fee = 0;
t.value = 1; // 1 wei. t.value = 1000000000; // 1e9 wei.
t.receiveAddress = me.addr; t.receiveAddress = me.address();
t.sign(myMiner.priv); t.sign(myMiner.secret());
tx = t.rlp(); tx = t.rlp();
} }
cout << RLP(tx) << endl; cout << RLP(tx) << endl;
s.execute(tx); s.execute(tx);
// TODO: Mine to set in stone. s.commitToMine(bc);
while (!s.mine(100)) {}
bc.attemptImport(s.blockData());
s.sync(bc);
return 0; return 0;
} }