github.com/annchain/OG@v0.0.9/tests/genesis_account/genesis_test.go (about) 1 package genesis_account 2 3 import ( 4 "encoding/json" 5 "fmt" 6 ogcrypto2 "github.com/annchain/OG/deprecated/ogcrypto" 7 "io/ioutil" 8 "testing" 9 ) 10 11 type PublicAccount struct { 12 Address string `json:"address"` 13 Balance uint64 `json:"balance"` 14 } 15 16 type Account struct { 17 PublicAccount 18 PublicKey string 19 PrivateKey string 20 } 21 22 type genesis struct { 23 Accounts []PublicAccount `json:"accounts"` 24 } 25 26 type secretGenesis struct { 27 Accounts []Account `json:"accounts"` 28 } 29 30 func TestAccount(t *testing.T) { 31 signer := ogcrypto2.SignerSecp256k1{} 32 var se secretGenesis 33 var ge genesis 34 for i := 0; i < 7; i++ { 35 pub, priv := signer.RandomKeyPair() 36 if err != nil { 37 t.Fatal(err) 38 } 39 publicAccount := PublicAccount{ 40 Address: pub.Address().String(), 41 Balance: 1000000, 42 } 43 account := Account{ 44 PublicAccount: publicAccount, 45 PrivateKey: priv.String(), 46 PublicKey: pub.String(), 47 } 48 se.Accounts = append(se.Accounts, account) 49 ge.Accounts = append(ge.Accounts, publicAccount) 50 } 51 52 data, err := json.MarshalIndent(ge, "", "\t") 53 if err != nil { 54 t.Fatal(err) 55 } 56 err = ioutil.WriteFile("genesis.json", data, 0644) 57 if err != nil { 58 t.Fatal(err) 59 } 60 data, err = json.MarshalIndent(se, "", "\t") 61 if err != nil { 62 t.Fatal(err) 63 } 64 err = ioutil.WriteFile("secret.json", data, 0644) 65 if err != nil { 66 t.Fatal(err) 67 } 68 69 var se2 secretGenesis 70 err = json.Unmarshal(data, &se2) 71 if err != nil { 72 t.Fatal(err) 73 } 74 d, _ := json.MarshalIndent(se2, "", "\t") 75 fmt.Println(string(d)) 76 77 } 78 79 func TestNewAccount(t *testing.T) { 80 signer := ogcrypto2.SignerSecp256k1{} 81 pub, priv := signer.RandomKeyPair() 82 if err != nil { 83 t.Fatal(err) 84 } 85 fmt.Println(pub, priv) 86 }