mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
add yang's test scripts
This commit is contained in:
parent
9329119ae7
commit
9c80a48898
4 changed files with 93 additions and 5 deletions
26
2nodetest.sh
Executable file
26
2nodetest.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
Datadir0="~/.mainnode"
|
||||
Datadir1="~/.peernode"
|
||||
|
||||
#build/bin/geth --datadir $Datadir0 removedb
|
||||
#build/bin/geth --datadir $Datadir1 removedb
|
||||
|
||||
rm -rf ~/.ethash
|
||||
rm -rf $Datadir0
|
||||
rm -rf $Datadir1
|
||||
|
||||
echo "node datadir cleared"
|
||||
|
||||
echo "main node init"
|
||||
build/bin/geth --datadir $Datadir0 init genesis.json
|
||||
build/bin/geth --datadir $Datadir0 --port 30303 --networkid 9876 --exec 'loadScript("yapen/mainnode.js")' console &
|
||||
|
||||
sleep 4s
|
||||
|
||||
echo "peer node init"
|
||||
build/bin/geth --datadir $Datadir1 init genesis.json
|
||||
build/bin/geth --datadir $Datadir1 --port 30304 --networkid 9876 --exec 'loadScript("yapen/peernode.js")' console
|
||||
|
||||
echo "all command executed"
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
{ "config": {
|
||||
{
|
||||
"config": {
|
||||
"chainId": 987,
|
||||
"homesteadBlock": 0,
|
||||
"eip155Block": 0,
|
||||
|
|
@ -9,4 +9,3 @@
|
|||
"gasLimit": "0x8000000",
|
||||
"alloc": {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
yapen/mainnode.js
Normal file
40
yapen/mainnode.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
function sleep(milliseconds) {
|
||||
var start = new Date().getTime();
|
||||
for (var i = 0; i < 1e7; i++) {
|
||||
if ((new Date().getTime() - start) > milliseconds){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function interaction() {
|
||||
personal.newAccount("123456")
|
||||
acc0 = web3.eth.accounts[0]
|
||||
acc1 = web3.eth.accounts[1]
|
||||
console.log("[mainnode]: account list: " + eth.accounts)
|
||||
console.log("[mainnode]: acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
|
||||
console.log("[mainnode]: acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
|
||||
|
||||
miner.setEtherbase(eth.accounts[0])
|
||||
miner.start()
|
||||
|
||||
personal.unlockAccount(acc0, "123456")
|
||||
eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(1,"ether")})
|
||||
while (1) {
|
||||
balance0 = web3.fromWei(web3.eth.getBalance(acc0))
|
||||
balance1 = web3.fromWei(web3.eth.getBalance(acc1))
|
||||
if (balance0 >0 && balance1 > 0) {
|
||||
miner.stop()
|
||||
break
|
||||
}
|
||||
sleep(1000)
|
||||
}
|
||||
console.log("[mainnode]: acc0 balance: " + web3.fromWei(web3.eth.getBalance(acc0)))
|
||||
console.log("[mainnode]: acc1 balance: " + web3.fromWei(web3.eth.getBalance(acc1)))
|
||||
|
||||
console.log("[mainnode]: admin.nodeInfo: " + admin.nodeInfo.id)
|
||||
|
||||
sleep(5000)
|
||||
}
|
||||
|
||||
interaction()
|
||||
23
yapen/peernode.js
Normal file
23
yapen/peernode.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
function sleep(milliseconds) {
|
||||
var start = new Date().getTime();
|
||||
for (var i = 0; i < 1e7; i++) {
|
||||
if ((new Date().getTime() - start) > milliseconds){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function interaction() {
|
||||
console.log("[peermode]: peer count: " + net.peerCount)
|
||||
//admin.addPeer("enode://a321db2296eb0078fab331d27460456f9c66c478049ee34441595d9c4fc4391af31f24b81fcdf21f28a7e391d07ab4fc550b6e235021abad310992f32d2fc876@127.0.0.1:30303")
|
||||
|
||||
console.log("[peermode]: connect to [::]:30303")
|
||||
admin.addPeer("enode://07a0106f92170dd3fc3ffa201c5b0708c8b3b92f73ad58b6f21a43338eea924b53e0a1d942c70f582127f10fb86b569c10dabcc97fa308a90f23aa6003c5b76c@[::]:30303")
|
||||
while (net.peerCount == 0)
|
||||
{
|
||||
sleep(1000)
|
||||
console.log("[peermode]: peer count: " + net.peerCount)
|
||||
}
|
||||
}
|
||||
|
||||
interaction()
|
||||
Loading…
Reference in a new issue