MCPcopy Create free account
hub / github.com/CPChain/chain / TestExtendCanonicalBlocks

Function TestExtendCanonicalBlocks

core/blockchain_test.go:174–196  ·  view source on GitHub ↗

Tests that given a starting canonical chain of a given size, it can be extended with various length chains.

(t *testing.T)

Source from the content-addressed store, hash-verified

172// Tests that given a starting canonical chain of a given size, it can be extended
173// with various length chains.
174func TestExtendCanonicalBlocks(t *testing.T) {
175 length := 5
176
177 db := database.NewMemDatabase()
178 processor, err := newCanonical(fakeDpor(db), length, db)
179 // Make first chain starting from genesis
180 if err != nil {
181 t.Fatalf("failed to make new canonical chain: %v", err)
182 }
183 defer processor.Stop()
184
185 // Define the difficulty comparator
186 better := func(td1, td2 *big.Int) {
187 if td2.Cmp(td1) <= 0 {
188 t.Errorf("total difficulty mismatch: have %v, expected more than %v", td2, td1)
189 }
190 }
191 // Start fork from current height
192 testFork(t, processor, length, 1, better)
193 testFork(t, processor, length, 2, better)
194 testFork(t, processor, length, 5, better)
195 testFork(t, processor, length, 10, better)
196}
197
198// Tests that given a starting canonical chain of a given size, creating shorter
199// forks do not take canonical ownership.

Callers

nothing calls this directly

Calls 5

newCanonicalFunction · 0.85
fakeDporFunction · 0.85
testForkFunction · 0.85
CmpMethod · 0.80
StopMethod · 0.65

Tested by

no test coverage detected