func testCoreRandom(N int) error { chainID := "test_chainID" genBytes, privVals, err := coreRandom(N, chainID) if err != nil { return err } if len(privVals) != N { return fmt.Errorf("len(privVals) != N") } // make sure each validator is in the genesis and all genesi are the same for i, v := range privVals { dirFlag := DirFlag if N > 1 { dirFlag = path.Join(DirFlag, fmt.Sprintf("%s_%d", chainID, i)) } b, err := ioutil.ReadFile(path.Join(dirFlag, "genesis.json")) if err != nil { return err } if !bytes.Equal(b, genBytes) { return fmt.Errorf("written genesis.json different from returned by coreRandom") } db := dbm.NewMemDB() gDoc, _ := sm.MakeGenesisStateFromFile(db, path.Join(dirFlag, "genesis.json")) if len(gDoc.Validators) != N { return fmt.Errorf("Expected %d validators. Got %d", N, len(gDoc.Validators)) } privVal := types.LoadPrivValidator(path.Join(dirFlag, "priv_validator.json")) if !bytes.Equal(privVal.Address, v.Address) { return fmt.Errorf("priv_validator file contents different than result of coreRandom") } var found bool for _, val := range gDoc.Validators { if bytes.Equal(val.UnbondTo[0].Address, privVal.Address) { found = true } } if !found { return fmt.Errorf("failed to find validator %d:%X in genesis.json", i, v.Address) } } return nil }
func testKnownCSV(csvFile string, csv GenDoc) error { chainID := "test_chainID" if err := ioutil.WriteFile(path.Join(DirFlag, "accounts.csv"), []byte(csvFile), 0600); err != nil { return err } genBytes, err := coreKnown(chainID, path.Join(DirFlag, "accounts.csv")) if err != nil { return err } if err := ioutil.WriteFile(path.Join(DirFlag, "genesis.json"), genBytes, 0600); err != nil { return err } db := dbm.NewMemDB() gDoc, _ := sm.MakeGenesisStateFromFile(db, path.Join(DirFlag, "genesis.json")) N := len(csv.pubkeys) if len(gDoc.Validators) != N { return fmt.Errorf("Expected %d validators. Got %d", N, len(gDoc.Validators)) } for i, pub := range csv.pubkeys { pubBytes, _ := hex.DecodeString(pub) if !bytes.Equal(gDoc.Validators[i].PubKey[:], pubBytes) { return fmt.Errorf("failed to find validator %d:%X in genesis.json", i, pub) } if len(csv.amts) > 0 && gDoc.Accounts[i].Amount != int64(csv.amts[i]) { return fmt.Errorf("amts dont match. got %d, expected %d", gDoc.Accounts[i].Amount, csv.amts[i]) } if len(csv.perms) > 0 && gDoc.Accounts[i].Permissions.Base.Perms != ptypes.PermFlag(csv.perms[i]) { return fmt.Errorf("perms dont match. got %d, expected %d", gDoc.Accounts[i].Permissions.Base.Perms, csv.perms[i]) } if len(csv.setbits) > 0 && gDoc.Accounts[i].Permissions.Base.SetBit != ptypes.PermFlag(csv.setbits[i]) { return fmt.Errorf("setbits dont match. got %d, expected %d", gDoc.Accounts[i].Permissions.Base.SetBit, csv.setbits[i]) } } return nil }