The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/staking/slash/interface_test.go

50 lines
1.2 KiB

package slash
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/shard"
staking "github.com/harmony-one/harmony/staking/types"
"github.com/pkg/errors"
)
var (
errFakeChainUnexpectEpoch = errors.New("epoch not expected")
)
type fakeBlockChain struct {
config params.ChainConfig
currentBlock types.Block
superCommittee shard.State
snapshots map[common.Address]staking.ValidatorWrapper
}
func (bc *fakeBlockChain) Config() *params.ChainConfig {
return &bc.config
}
func (bc *fakeBlockChain) CurrentBlock() *types.Block {
return &bc.currentBlock
}
func (bc *fakeBlockChain) ReadShardState(epoch *big.Int) (*shard.State, error) {
if epoch.Cmp(big.NewInt(currentEpoch)) == 0 {
return nil, errFakeChainUnexpectEpoch
}
return &bc.superCommittee, nil
}
func (bc *fakeBlockChain) ReadValidatorSnapshotAtEpoch(epoch *big.Int, addr common.Address) (*staking.ValidatorSnapshot, error) {
vw, ok := bc.snapshots[addr]
if !ok {
return nil, errors.New("missing snapshot")
}
return &staking.ValidatorSnapshot{
Validator: &vw,
Epoch: new(big.Int).Set(epoch),
}, nil
}