Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed Feb 19, 2024
1 parent bf4f34e commit 3bdb0ef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Executor struct {

// this value should be set if we want to enable validator set precompile
// note that this precompile WONT be enabled for WriteGenesis
validatorSetBackend precompiled.ValidatoSetPrecompileBackend
validatorSetBackend precompiled.ValidatorSetPrecompileBackend
}

// NewExecutor creates a new executor
Expand Down Expand Up @@ -239,7 +239,7 @@ func (e *Executor) BeginTxn(
return t, nil
}

func (e *Executor) SetValidatorSetBackend(validatorSetBackend precompiled.ValidatoSetPrecompileBackend) {
func (e *Executor) SetValidatorSetBackend(validatorSetBackend precompiled.ValidatorSetPrecompileBackend) {
e.validatorSetBackend = validatorSetBackend
}

Expand Down Expand Up @@ -281,7 +281,7 @@ type Transition struct {
}

func NewTransition(logger hclog.Logger, config chain.ForksInTime,
snap Snapshot, radix *Txn, validatorSetBackend precompiled.ValidatoSetPrecompiledBackend) *Transition {
snap Snapshot, radix *Txn, validatorSetBackend precompiled.ValidatorSetPrecompileBackend) *Transition {
return &Transition{
logger: logger,
config: config,
Expand Down
4 changes: 2 additions & 2 deletions state/runtime/precompiled/precompiled.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ type Precompiled struct {
}

// NewPrecompiled creates a new runtime for the precompiled contracts
func NewPrecompiled(validatorSetBackend ValidatoSetPrecompileBackend) *Precompiled {
func NewPrecompiled(validatorSetBackend ValidatorSetPrecompileBackend) *Precompiled {
p := &Precompiled{}
p.setupContracts(validatorSetBackend)

return p
}

func (p *Precompiled) setupContracts(validatorSetBackend ValidatoSetPrecompileBackend) {
func (p *Precompiled) setupContracts(validatorSetBackend ValidatorSetPrecompileBackend) {
p.register("1", &ecrecover{p})
p.register("2", &sha256h{})
p.register("3", &ripemd160h{p})
Expand Down
6 changes: 3 additions & 3 deletions state/runtime/precompiled/validator_set_precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var (
errValidatorSetPrecompileNotEnabled = errors.New("validator set precompile is not enabled")
)

type ValidatoSetPrecompileBackend interface {
type ValidatorSetPrecompileBackend interface {
GetValidatorsForBlock(blockNumber uint64) (validator.AccountSet, error)
}

type validatorSetPrecompile struct {
backend ValidatoSetPrecompileBackend
backend ValidatorSetPrecompileBackend
}

// gas returns the gas required to execute the pre-compiled contract
Expand Down Expand Up @@ -82,7 +82,7 @@ func (c *validatorSetPrecompile) run(input []byte, caller types.Address, host ru
return abiBoolFalse, nil
}

func createValidatorSet(blockNumber uint64, backend ValidatoSetPrecompileBackend) (validator.ValidatorSet, error) {
func createValidatorSet(blockNumber uint64, backend ValidatorSetPrecompileBackend) (validator.ValidatorSet, error) {
if backend == nil {
return nil, errValidatorSetPrecompileNotEnabled
}
Expand Down
21 changes: 21 additions & 0 deletions state/runtime/precompiled/validator_set_precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ func Test_ValidatorSetPrecompile_run_HasQuorum(t *testing.T) {
assert.Equal(t, abiBoolFalse, v)
}

func Test_abiDecodeAddresses_Error(t *testing.T) {
dummy1 := [31]byte{}
dummy2 := [62]byte{}
dummy3 := [64]byte{}
dummy4 := [96]byte{}
dummy4[31] = 32
dummy4[63] = 10

_, err := abiDecodeAddresses(dummy1[:])
require.ErrorIs(t, err, runtime.ErrInvalidInputData)

_, err = abiDecodeAddresses(dummy2[:])
require.ErrorIs(t, err, runtime.ErrInvalidInputData)

_, err = abiDecodeAddresses(dummy3[:])
require.ErrorIs(t, err, runtime.ErrInvalidInputData)

_, err = abiDecodeAddresses(dummy4[:])
require.ErrorIs(t, err, runtime.ErrInvalidInputData)
}

type validatorSetBackendMock struct {
mock.Mock
}
Expand Down

0 comments on commit 3bdb0ef

Please sign in to comment.