Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjfh committed Dec 4, 2024
1 parent 129abeb commit 50443f3
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions tests/test_forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ proc forkedChainMain*() =
check com.wdWritten(blk3) == 3
check chain.validate info & " (9)"

test "newBase == oldBase, fork and keep on that fork":
test "newBase == oldBase, fork and stay on that fork":
const info = "newBase == oldBase, fork .."
let com = env.newCom()

Expand All @@ -266,7 +266,7 @@ proc forkedChainMain*() =
check chain.latestHash == B7.blockHash
check chain.validate info & " (9)"

test "newBase == cursor, fork and keep on that fork":
test "newBase == cursor, fork and stay on that fork":
const info = "newBase == cursor, fork .."
let com = env.newCom()

Expand Down Expand Up @@ -294,8 +294,8 @@ proc forkedChainMain*() =
check chain.latestHash == B7.blockHash
check chain.validate info & " (9)"

test "newBase between oldBase and cursor, fork and keep on that fork":
const info = "newBase between oldBase .."
test "newBase on shorter canonical arc, discard arc with oldBase":
const info = "newBase on shorter canonical .."
let com = env.newCom()

var chain = newForkedChain(com, com.genesisHeader, baseDistance = 3)
Expand All @@ -318,6 +318,37 @@ proc forkedChainMain*() =

check com.headHash == B7.blockHash
check chain.latestHash == B7.blockHash
check chain.baseNumber >= B4.header.number
check chain.cursorHeads.len == 1
check chain.validate info & " (9)"

test "newBase on curbed non-canonical arc":
const info = "newBase on curbed non-canonical .."
let com = env.newCom()

var chain = newForkedChain(com, com.genesisHeader, baseDistance = 5)
check chain.importBlock(blk1).isOk
check chain.importBlock(blk2).isOk
check chain.importBlock(blk3).isOk
check chain.importBlock(blk4).isOk
check chain.importBlock(blk5).isOk
check chain.importBlock(blk6).isOk
check chain.importBlock(blk7).isOk

check chain.importBlock(B4).isOk
check chain.importBlock(B5).isOk
check chain.importBlock(B6).isOk
check chain.importBlock(B7).isOk
check chain.validate info & " (1)"

check chain.forkChoice(B7.blockHash, B5.blockHash).isOk
check chain.validate info & " (2)"

check com.headHash == B7.blockHash
check chain.latestHash == B7.blockHash
check chain.baseNumber > 0
check chain.baseNumber < B4.header.number
check chain.cursorHeads.len == 2
check chain.validate info & " (9)"

test "newBase == oldBase, fork and return to old chain":
Expand Down Expand Up @@ -374,8 +405,9 @@ proc forkedChainMain*() =
check chain.latestHash == blk7.blockHash
check chain.validate info & " (9)"

test "newBase between oldBase and cursor, fork and return to old chain, switch to new chain":
const info = "newBase between oldBase and .."
test "newBase on shorter canonical arc, discard arc with oldBase" &
" (ign dup block)":
const info = "newBase on shorter canonical .."
let com = env.newCom()

var chain = newForkedChain(com, com.genesisHeader, baseDistance = 3)
Expand All @@ -400,10 +432,12 @@ proc forkedChainMain*() =

check com.headHash == B7.blockHash
check chain.latestHash == B7.blockHash
check chain.baseNumber >= B4.header.number
check chain.cursorHeads.len == 1
check chain.validate info & " (9)"

test "newBase between oldBase and cursor, fork and return to old chain":
const info = "newBase between oldBase and .."
test "newBase on longer canonical arc, discard arc with oldBase":
const info = "newBase on longer canonical .."
let com = env.newCom()

var chain = newForkedChain(com, com.genesisHeader, baseDistance = 3)
Expand All @@ -426,6 +460,9 @@ proc forkedChainMain*() =

check com.headHash == blk7.blockHash
check chain.latestHash == blk7.blockHash
check chain.baseNumber > 0
check chain.baseNumber < blk5.header.number
check chain.cursorHeads.len == 1
check chain.validate info & " (9)"

test "headerByNumber":
Expand Down

0 comments on commit 50443f3

Please sign in to comment.