mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-01 15:57:39 +00:00
sharding: test for adding header at the wrong period
Former-commit-id: af8d4bebd7d9d9478d543482a43f450444893b50 [formerly 4913424a3a91032b3fee76ccd805c3b6a8926271] Former-commit-id: a48c6f7a508549f89ec66a9bc8ba72ecac03e784
This commit is contained in:
parent
ea13800459
commit
6dd7261bd1
@ -638,7 +638,7 @@ func TestNormalAddHeader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddHeadersInSamePeriod(t *testing.T) {
|
||||
func TestAddTwoHeadersAtSamePeriod(t *testing.T) {
|
||||
addr := crypto.PubkeyToAddress(mainKey.PublicKey)
|
||||
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance2000Eth}})
|
||||
txOpts := bind.NewKeyedTransactor(mainKey)
|
||||
@ -674,4 +674,55 @@ func TestAddHeadersInSamePeriod(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("Proposer is not allowed to add 2 headers within same period")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddHeadersAtWrongPeriod(t *testing.T) {
|
||||
addr := crypto.PubkeyToAddress(mainKey.PublicKey)
|
||||
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance2000Eth}})
|
||||
txOpts := bind.NewKeyedTransactor(mainKey)
|
||||
_, _, smc, _ := deploySMCContract(backend, mainKey)
|
||||
|
||||
// Fast forward to the next period to submit header. Period 1
|
||||
for i := 0; i < int(sharding.PeriodLength); i++ {
|
||||
backend.Commit()
|
||||
}
|
||||
|
||||
// Proposer adds header at wrong period, shard 0, period 0 and chunkroot 0xA
|
||||
period0 := big.NewInt(0)
|
||||
shard0 := big.NewInt(0)
|
||||
chunkRoot := [32]byte{'A'}
|
||||
chunkRootEmpty := [32]byte{}
|
||||
_, err := smc.AddHeader(txOpts, shard0, period0, chunkRoot)
|
||||
if err == nil {
|
||||
t.Errorf("Proposer adds header at wrong period should have failed")
|
||||
}
|
||||
|
||||
cr, err := smc.CollationRecords(&bind.CallOpts{}, shard0, period0)
|
||||
if cr.ChunkRoot != chunkRootEmpty {
|
||||
t.Errorf("Chunkroot mismatched. Want: %v, Got: %v", chunkRoot, cr)
|
||||
}
|
||||
|
||||
// Proposer adds header at wrong period, shard 0, period 2 and chunkroot 0xA
|
||||
period2 := big.NewInt(2)
|
||||
_, err = smc.AddHeader(txOpts, shard0, period2, chunkRoot)
|
||||
if err == nil {
|
||||
t.Errorf("Proposer adds header at wrong period should have failed")
|
||||
}
|
||||
|
||||
cr, err = smc.CollationRecords(&bind.CallOpts{}, shard0, period2)
|
||||
if cr.ChunkRoot != chunkRootEmpty {
|
||||
t.Errorf("Chunkroot mismatched. Want: %v, Got: %v", chunkRoot, cr)
|
||||
}
|
||||
|
||||
// Proposer adds header at correct period, shard 0, period 1 and chunkroot 0xA
|
||||
period1 := big.NewInt(1)
|
||||
_, err = smc.AddHeader(txOpts, shard0, period1, chunkRoot)
|
||||
if err != nil {
|
||||
t.Fatalf("Proposer adds header failed: %v", err)
|
||||
}
|
||||
|
||||
cr, err = smc.CollationRecords(&bind.CallOpts{}, shard0, period1)
|
||||
if cr.ChunkRoot != chunkRootEmpty {
|
||||
t.Errorf("Chunkroot mismatched. Want: %v, Got: %v", chunkRoot, cr)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user