diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-29 09:20:57 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | f3135faaddd6a2af7125471ed37fc13571a8be91 (patch) | |
tree | 1e9bccc7fa1ae09895bc1126e4140983858221e5 /test | |
parent | 790eaf95a6c4c81b02587bf8800f4cad22130e56 (diff) | |
download | dexon-f3135faaddd6a2af7125471ed37fc13571a8be91.tar.gz dexon-f3135faaddd6a2af7125471ed37fc13571a8be91.tar.zst dexon-f3135faaddd6a2af7125471ed37fc13571a8be91.zip |
test: improve keygen.go (#62)
Diffstat (limited to 'test')
-rw-r--r-- | test/keygen.go | 69 | ||||
-rw-r--r-- | test/keystore/bootnode.key (renamed from test/bootnode.key) | 0 | ||||
-rw-r--r-- | test/keystore/monkey.key (renamed from test/testkey) | 0 | ||||
-rw-r--r-- | test/keystore/rpc.key (renamed from test/testrpc.nodekey) | 0 | ||||
-rw-r--r-- | test/keystore/test0.key (renamed from test/test0.nodekey) | 0 | ||||
-rw-r--r-- | test/keystore/test1.key (renamed from test/test1.nodekey) | 0 | ||||
-rw-r--r-- | test/keystore/test2.key (renamed from test/test2.nodekey) | 0 | ||||
-rw-r--r-- | test/keystore/test3.key (renamed from test/test3.nodekey) | 0 | ||||
-rwxr-xr-x | test/run_test.sh | 11 |
9 files changed, 67 insertions, 13 deletions
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/bootnode.key b/test/keystore/bootnode.key index fadd4b3a2..fadd4b3a2 100644 --- a/test/bootnode.key +++ b/test/keystore/bootnode.key diff --git a/test/testkey b/test/keystore/monkey.key index a9fe18413..a9fe18413 100644 --- a/test/testkey +++ b/test/keystore/monkey.key diff --git a/test/testrpc.nodekey b/test/keystore/rpc.key index c9b475816..c9b475816 100644 --- a/test/testrpc.nodekey +++ b/test/keystore/rpc.key diff --git a/test/test0.nodekey b/test/keystore/test0.key index 5ecbc48a6..5ecbc48a6 100644 --- a/test/test0.nodekey +++ b/test/keystore/test0.key diff --git a/test/test1.nodekey b/test/keystore/test1.key index c16f73286..c16f73286 100644 --- a/test/test1.nodekey +++ b/test/keystore/test1.key diff --git a/test/test2.nodekey b/test/keystore/test2.key index 402577df2..402577df2 100644 --- a/test/test2.nodekey +++ b/test/keystore/test2.key diff --git a/test/test3.nodekey b/test/keystore/test3.key index b706958d6..b706958d6 100644 --- a/test/test3.nodekey +++ b/test/keystore/test3.key 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)) \ |