|
8 | 8 |
|
9 | 9 | gigaconfig "github.com/sei-protocol/sei-chain/giga/config" |
10 | 10 | "github.com/sei-protocol/sei-chain/giga/evmonly/precompiles" |
11 | | - "github.com/sei-protocol/sei-chain/giga/evmonly/precompiles/solstorage" |
12 | 11 | "github.com/sei-protocol/sei-chain/giga/evmonly/precompiles/staking" |
13 | 12 | seidbconfig "github.com/sei-protocol/sei-chain/sei-db/config" |
14 | 13 | "github.com/sei-protocol/sei-chain/sei-tendermint/autobahn/types" |
@@ -39,27 +38,18 @@ func (g stakingGenesis) EndBlock(block precompiles.BlockContext, state precompil |
39 | 38 | return g.Precompile.EndBlock(block, state) |
40 | 39 | } |
41 | 40 |
|
42 | | -// corruptEpochSnapshot stores an epoch snapshot longer than staking allows at |
43 | | -// every EndBlock. |
44 | | -type corruptEpochSnapshot struct { |
| 41 | +// corruptBondedSet stores a bonded set longer than staking allows at every |
| 42 | +// EndBlock. |
| 43 | +type corruptBondedSet struct { |
45 | 44 | staking.Precompile |
46 | 45 | } |
47 | 46 |
|
48 | | -func (corruptEpochSnapshot) EndBlock(_ precompiles.BlockContext, state precompiles.State) ([]error, error) { |
49 | | - // Slot 2 of StakingStorage maps each epoch to its snapshot, and slot 3 holds |
50 | | - // the epoch after the latest. |
51 | | - state.SetState(staking.Address, solstorage.MapUint64(solstorage.Slot(2), 0), common.BigToHash(big.NewInt(101))) |
52 | | - state.SetState(staking.Address, solstorage.Slot(3), common.BigToHash(big.NewInt(1))) |
| 47 | +func (corruptBondedSet) EndBlock(_ precompiles.BlockContext, state precompiles.State) ([]error, error) { |
| 48 | + // Slot 0 of StakingStorage holds the bonded set's length. |
| 49 | + state.SetState(staking.Address, common.Hash{}, common.BigToHash(big.NewInt(101))) |
53 | 50 | return nil, nil |
54 | 51 | } |
55 | 52 |
|
56 | | -// evmOnlyTestClosingBlock returns an empty block at height that closes epoch. |
57 | | -func evmOnlyTestClosingBlock(height int64, epoch types.EpochIndex) *proxy.RequestFinalizeBlock { |
58 | | - req := evmOnlyTestBlock(height) |
59 | | - req.Header.ClosingEpoch = utils.Some(epoch) |
60 | | - return req |
61 | | -} |
62 | | - |
63 | 53 | // newStakingEVMOnlyTestApp returns an initialized application serving the |
64 | 54 | // configured validators and running staking as contract. |
65 | 55 | func newStakingEVMOnlyTestApp(t *testing.T, configured []proxy.ValidatorUpdate, contract precompiles.Contract) proxy.EVMApplication { |
@@ -98,20 +88,17 @@ func testGenesisValidator(operator common.Address, key ed25519.PublicKey, self i |
98 | 88 | } |
99 | 89 | } |
100 | 90 |
|
101 | | -func TestEVMOnlyApplicationServesStakingsSetAtEachEpochEnd(t *testing.T) { |
| 91 | +func TestEVMOnlyApplicationServesStakingsBondedSet(t *testing.T) { |
102 | 92 | configured := []proxy.ValidatorUpdate{{PubKey: autobahnKey(ed25519.TestSecretKey([]byte("configured")).Public()), Power: 1}} |
103 | 93 | key1 := ed25519.TestSecretKey([]byte("validator-1")).Public() |
104 | 94 | key2 := ed25519.TestSecretKey([]byte("validator-2")).Public() |
105 | 95 | app := newStakingEVMOnlyTestApp(t, configured, stakingGenesis{validators: []staking.GenesisValidator{ |
106 | 96 | testGenesisValidator(common.HexToAddress("0xa2"), key2, 20), |
107 | 97 | testGenesisValidator(common.HexToAddress("0xa1"), key1, 30), |
108 | 98 | }}) |
109 | | - require.Equal(t, configured, app.GetValidators(), "the configured validators serve until staking snapshots a set") |
| 99 | + require.Equal(t, configured, app.GetValidators(), "the configured validators serve until staking bonds a set") |
110 | 100 |
|
111 | 101 | finalizeAndCommitEVMOnlyTestBlock(t, app, evmOnlyTestBlock(1)) |
112 | | - require.Equal(t, configured, app.GetValidators(), "staking bonded a set, but no epoch has ended") |
113 | | - |
114 | | - finalizeAndCommitEVMOnlyTestBlock(t, app, evmOnlyTestClosingBlock(2, 0)) |
115 | 102 | require.Equal(t, []proxy.ValidatorUpdate{ |
116 | 103 | {PubKey: autobahnKey(key1), Power: 30}, |
117 | 104 | {PubKey: autobahnKey(key2), Power: 20}, |
@@ -139,8 +126,8 @@ func TestEVMOnlyApplicationServesNoValidatorsAfterAFailedCommit(t *testing.T) { |
139 | 126 | require.Empty(t, app.GetValidators(), "block 1 failed to commit, so the committed state predates it") |
140 | 127 | } |
141 | 128 |
|
142 | | -func TestEVMOnlyApplicationServesNoValidatorsFromACorruptEpochSnapshot(t *testing.T) { |
143 | | - app := newStakingEVMOnlyTestApp(t, []proxy.ValidatorUpdate{{Power: 1}}, corruptEpochSnapshot{}) |
| 129 | +func TestEVMOnlyApplicationServesNoValidatorsFromACorruptBondedSet(t *testing.T) { |
| 130 | + app := newStakingEVMOnlyTestApp(t, []proxy.ValidatorUpdate{{Power: 1}}, corruptBondedSet{}) |
144 | 131 | finalizeAndCommitEVMOnlyTestBlock(t, app, evmOnlyTestBlock(1)) |
145 | 132 | require.Empty(t, app.GetValidators()) |
146 | 133 | } |
|
0 commit comments