From 3bc8c1628257b2fab50f260e048118fc56b1ab02 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Thu, 29 Nov 2018 09:20:57 +0800 Subject: test: improve keygen.go (#62) --- test/bootnode.key | 1 - test/keygen.go | 69 +++++++++++++++++++++++++++++++++++++++------- test/keystore/bootnode.key | 1 + test/keystore/monkey.key | 1 + test/keystore/rpc.key | 1 + test/keystore/test0.key | 1 + test/keystore/test1.key | 1 + test/keystore/test2.key | 1 + test/keystore/test3.key | 1 + test/run_test.sh | 11 ++++++-- test/test0.nodekey | 1 - test/test1.nodekey | 1 - test/test2.nodekey | 1 - test/test3.nodekey | 1 - test/testkey | 1 - test/testrpc.nodekey | 1 - 16 files changed, 74 insertions(+), 20 deletions(-) delete mode 100644 test/bootnode.key create mode 100644 test/keystore/bootnode.key create mode 100644 test/keystore/monkey.key create mode 100644 test/keystore/rpc.key create mode 100644 test/keystore/test0.key create mode 100644 test/keystore/test1.key create mode 100644 test/keystore/test2.key create mode 100644 test/keystore/test3.key delete mode 100644 test/test0.nodekey delete mode 100644 test/test1.nodekey delete mode 100644 test/test2.nodekey delete mode 100644 test/test3.nodekey delete mode 100644 test/testkey delete mode 100644 test/testrpc.nodekey (limited to 'test') diff --git a/test/bootnode.key b/test/bootnode.key deleted file mode 100644 index fadd4b3a2..000000000 --- a/test/bootnode.key +++ /dev/null @@ -1 +0,0 @@ -8fde5e98ab761307a68a5ebd8dee1d9def2f2f4c664a676eaa6896fbf13a58ef \ No newline at end of file diff --git a/test/keygen.go b/test/keygen.go index 5397bc269..b98d70751 100644 --- a/test/keygen.go +++ b/test/keygen.go @@ -1,34 +1,83 @@ package main import ( - "encoding/hex" + "encoding/json" "fmt" + "io/ioutil" + "math/big" "os" "strconv" + "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/crypto" ) +const genesisFile = "genesis.json" + +var preFundAmount *big.Int = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e8)) + +var preFundAddresss = []string{ + "0x2a9D669e4791845EED01D4c0ffF3B927cC94A884", + "0x1245A8672FA881Cf858eF01D34c42B55D9b263fF", + "0xe0F859340353854693F537ea337106a33E9FeAB0", +} + func main() { + data, err := ioutil.ReadFile(genesisFile) + if err != nil { + panic(err) + } + + genesis := new(core.Genesis) + if err := json.Unmarshal(data, &genesis); err != nil { + panic(err) + } + + // Clear previous allocation. + genesis.Alloc = make(map[common.Address]core.GenesisAccount) + count, err := strconv.Atoi(os.Args[1]) if err != nil { panic(err) } + for _, addr := range preFundAddresss { + address := common.HexToAddress(addr) + genesis.Alloc[address] = core.GenesisAccount{ + Balance: preFundAmount, + Staked: big.NewInt(0), + } + fmt.Printf("Created account %s\n", address.String()) + } for i := 0; i < count; i++ { privKey, err := crypto.GenerateKey() if err != nil { panic(err) } - address := crypto.PubkeyToAddress(privKey.PublicKey).String() - pk := hex.EncodeToString(crypto.FromECDSAPub(&privKey.PublicKey)) + crypto.SaveECDSA(fmt.Sprintf("keystore/test%d.key", i), privKey) + + address := crypto.PubkeyToAddress(privKey.PublicKey) + genesis.Alloc[address] = core.GenesisAccount{ + Balance: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)), + Staked: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(5e5)), + PublicKey: crypto.FromECDSAPub(&privKey.PublicKey), + NodeInfo: core.NodeInfo{ + Name: fmt.Sprintf("DEXON Test Node %d", i), + Email: fmt.Sprintf("dexon%d@dexon.org", i), + Location: "Taipei, Taiwan", + Url: "https://dexon.org", + }, + } + fmt.Printf("Created account %s\n", address.String()) + } - fmt.Printf(` - "%s": { - "balance": "1000000000000000000000", - "staked": "500000000000000000000", - "publicKey": "0x%s" - },`, address, pk) + data, err = json.MarshalIndent(genesis, "", " ") + if err != nil { + panic(err) + } - crypto.SaveECDSA(fmt.Sprintf("test%d.nodekey", i), privKey) + if err := ioutil.WriteFile(genesisFile, data, 0644); err != nil { + panic(err) } + fmt.Println("Done.") } diff --git a/test/keystore/bootnode.key b/test/keystore/bootnode.key new file mode 100644 index 000000000..fadd4b3a2 --- /dev/null +++ b/test/keystore/bootnode.key @@ -0,0 +1 @@ +8fde5e98ab761307a68a5ebd8dee1d9def2f2f4c664a676eaa6896fbf13a58ef \ No newline at end of file diff --git a/test/keystore/monkey.key b/test/keystore/monkey.key new file mode 100644 index 000000000..a9fe18413 --- /dev/null +++ b/test/keystore/monkey.key @@ -0,0 +1 @@ +fa30b47a7a3d5ab6935d873ffaeb8ca5b9782d102c4094be6da6b7f2fc04b5bd \ No newline at end of file diff --git a/test/keystore/rpc.key b/test/keystore/rpc.key new file mode 100644 index 000000000..c9b475816 --- /dev/null +++ b/test/keystore/rpc.key @@ -0,0 +1 @@ +e48009e740ff5f47a42267d42d908499ea1e73bfef8d459855aa2ca889e8e6bd \ No newline at end of file diff --git a/test/keystore/test0.key b/test/keystore/test0.key new file mode 100644 index 000000000..5ecbc48a6 --- /dev/null +++ b/test/keystore/test0.key @@ -0,0 +1 @@ +3cf5bdee098cc34536a7b0e80d85e07a380efca76fc12136299b9e5ba24193c8 \ No newline at end of file diff --git a/test/keystore/test1.key b/test/keystore/test1.key new file mode 100644 index 000000000..c16f73286 --- /dev/null +++ b/test/keystore/test1.key @@ -0,0 +1 @@ +96c9f1435d53577db18d45411326311529a0e8affb19218e27f65769a482c0fb \ No newline at end of file diff --git a/test/keystore/test2.key b/test/keystore/test2.key new file mode 100644 index 000000000..402577df2 --- /dev/null +++ b/test/keystore/test2.key @@ -0,0 +1 @@ +b25e955e30dd87cbaec83287beea6ec9c4c72498bc66905590756bf48da5d1fc \ No newline at end of file diff --git a/test/keystore/test3.key b/test/keystore/test3.key new file mode 100644 index 000000000..b706958d6 --- /dev/null +++ b/test/keystore/test3.key @@ -0,0 +1 @@ +35577f65312f4a5e0b5391f5385043a6bc7b51fa4851a579e845b5fea33efded \ No newline at end of file diff --git a/test/run_test.sh b/test/run_test.sh index 7bcb0f688..5c4345925 100755 --- a/test/run_test.sh +++ b/test/run_test.sh @@ -10,7 +10,7 @@ NETWORK="${1}" if [ "$2" == "--local" ]; then NETWORK="${NETWORK} --bootnodes enode://0478aa13c91aa0db8e93b668313b7eb0532fbdb24f64772375373b14dbe326c238ad09ab4469f6442c9a9753f1275aeec2e531912c14a958ed1feb4ae7e227ef@127.0.0.1:30301" # Start bootnode. - bootnode -nodekey bootnode.key --verbosity=9 > bootnode.log 2>&1 & + bootnode -nodekey keystore/bootnode.key --verbosity=9 > bootnode.log 2>&1 & fi GDEX=../build/bin/gdex @@ -21,6 +21,11 @@ pkill -9 -f gdex logsdir=$PWD/log-$(date '+%Y-%m-%d-%H:%M:%S') mkdir $logsdir +if [ -e log-latest ]; then + rm -f log-previous + mv log-latest log-previous +fi + rm -f log-latest ln -s $logsdir log-latest @@ -32,7 +37,7 @@ $GDEX \ ${NETWORK} \ --verbosity=4 \ --gcmode=archive \ - --datadir=$datadir --nodekey=testrpc.nodekey \ + --datadir=$datadir --nodekey=keystore/rpc.key \ --rpc --rpcapi=eth,net,web3,debug \ --rpcaddr=0.0.0.0 --rpcport=8545 \ --ws --wsapi=eth,net,web3,debug \ @@ -50,7 +55,7 @@ for i in $(seq 0 3); do --bp \ --verbosity=4 \ --gcmode=archive \ - --datadir=$datadir --nodekey=test$i.nodekey \ + --datadir=$datadir --nodekey=keystore/test$i.key \ --port=$((30305 + $i)) \ --rpc --rpcapi=eth,net,web3,debug \ --rpcaddr=0.0.0.0 --rpcport=$((8547 + $i * 2)) \ diff --git a/test/test0.nodekey b/test/test0.nodekey deleted file mode 100644 index 5ecbc48a6..000000000 --- a/test/test0.nodekey +++ /dev/null @@ -1 +0,0 @@ -3cf5bdee098cc34536a7b0e80d85e07a380efca76fc12136299b9e5ba24193c8 \ No newline at end of file diff --git a/test/test1.nodekey b/test/test1.nodekey deleted file mode 100644 index c16f73286..000000000 --- a/test/test1.nodekey +++ /dev/null @@ -1 +0,0 @@ -96c9f1435d53577db18d45411326311529a0e8affb19218e27f65769a482c0fb \ No newline at end of file diff --git a/test/test2.nodekey b/test/test2.nodekey deleted file mode 100644 index 402577df2..000000000 --- a/test/test2.nodekey +++ /dev/null @@ -1 +0,0 @@ -b25e955e30dd87cbaec83287beea6ec9c4c72498bc66905590756bf48da5d1fc \ No newline at end of file diff --git a/test/test3.nodekey b/test/test3.nodekey deleted file mode 100644 index b706958d6..000000000 --- a/test/test3.nodekey +++ /dev/null @@ -1 +0,0 @@ -35577f65312f4a5e0b5391f5385043a6bc7b51fa4851a579e845b5fea33efded \ No newline at end of file diff --git a/test/testkey b/test/testkey deleted file mode 100644 index a9fe18413..000000000 --- a/test/testkey +++ /dev/null @@ -1 +0,0 @@ -fa30b47a7a3d5ab6935d873ffaeb8ca5b9782d102c4094be6da6b7f2fc04b5bd \ No newline at end of file diff --git a/test/testrpc.nodekey b/test/testrpc.nodekey deleted file mode 100644 index c9b475816..000000000 --- a/test/testrpc.nodekey +++ /dev/null @@ -1 +0,0 @@ -e48009e740ff5f47a42267d42d908499ea1e73bfef8d459855aa2ca889e8e6bd \ No newline at end of file -- cgit v1.2.3