MCPcopy Create free account
hub / github.com/DNAProject/DNA / newTestChainStore

Function newTestChainStore

consensus/vbft/chain_store_test.go:74–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

72}
73
74func newTestChainStore(t *testing.T) *ChainStore {
75 log.InitLog(log.InfoLog, log.Stdout)
76 var err error
77 acct := account.NewAccount("SHA256withECDSA")
78 if acct == nil {
79 t.Fatalf("GetDefaultAccount error: acc is nil")
80 }
81 os.RemoveAll(config.DEFAULT_DATA_DIR)
82 db, err := ledger.NewLedger(config.DEFAULT_DATA_DIR, 0)
83 if err != nil {
84 t.Fatalf("NewLedger error %s", err)
85 }
86
87 var bookkeepers []keypair.PublicKey
88 if len(testBookkeeperAccounts) == 0 {
89 for i := 0; i < 7; i++ {
90 acc := account.NewAccount("")
91 testBookkeeperAccounts = append(testBookkeeperAccounts, acc)
92 bookkeepers = append(bookkeepers, acc.PublicKey)
93 }
94 }
95
96 config.DefConfig.Genesis = testGenesisConfig
97 genesisConfig := config.DefConfig.Genesis
98
99 // update peers in genesis
100 for i, p := range genesisConfig.VBFT.Peers {
101 if i < len(testBookkeeperAccounts) {
102 p.PeerPubkey = vconfig.PubkeyID(testBookkeeperAccounts[i].PublicKey)
103 p.Address = testBookkeeperAccounts[i].Address.ToBase58()
104 }
105 }
106 block, err := genesis.BuildGenesisBlock(bookkeepers, genesisConfig)
107 if err != nil {
108 t.Fatalf("BuildGenesisBlock error %s", err)
109 }
110
111 err = db.Init(bookkeepers, block)
112 if err != nil {
113 t.Fatalf("InitLedgerStoreWithGenesisBlock error %s", err)
114 }
115 chainstore, err := OpenBlockStore(db, nil)
116 if err != nil {
117 t.Fatalf("openblockstore failed: %v\n", err)
118 }
119 return chainstore
120}
121
122func cleanTestChainStore() {
123 os.RemoveAll(config.DEFAULT_DATA_DIR)

Callers 2

buildTestBlockPoolFunction · 0.85
TestGetChainedBlockNumFunction · 0.85

Calls 8

InitMethod · 0.95
InitLogFunction · 0.92
NewAccountFunction · 0.92
NewLedgerFunction · 0.92
BuildGenesisBlockFunction · 0.92
OpenBlockStoreFunction · 0.85
FatalfMethod · 0.80
ToBase58Method · 0.80

Tested by

no test coverage detected