Skip to content

Commit

Permalink
add new blockchain hooks to mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
laurci committed Jul 16, 2024
1 parent 4985161 commit 95d5c78
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 14 deletions.
65 changes: 51 additions & 14 deletions mock/context/blockChainHookStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ var _ vmcommon.BlockchainHook = (*BlockchainHookStub)(nil)

// BlockchainHookStub is used in tests to check that interface methods were called
type BlockchainHookStub struct {
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
GetBlockHashCalled func(nonce uint64) ([]byte, error)
LastNonceCalled func() uint64
LastRoundCalled func() uint64
LastTimeStampCalled func() uint64
LastRandomSeedCalled func() []byte
LastEpochCalled func() uint32
GetStateRootHashCalled func() []byte
CurrentNonceCalled func() uint64
CurrentRoundCalled func() uint64
CurrentTimeStampCalled func() uint64
CurrentRandomSeedCalled func() []byte
CurrentEpochCalled func() uint32
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
GetBlockHashCalled func(nonce uint64) ([]byte, error)
LastNonceCalled func() uint64
LastRoundCalled func() uint64
LastTimeStampCalled func() uint64
LastRandomSeedCalled func() []byte
LastEpochCalled func() uint32
GetStateRootHashCalled func() []byte
CurrentNonceCalled func() uint64
CurrentRoundCalled func() uint64
CurrentTimeStampCalled func() uint64
CurrentRandomSeedCalled func() []byte
CurrentEpochCalled func() uint32
RoundTimeCalled func() uint64
EpochStartBlockTimeStampCalled func() uint64
EpochStartBlockNonceCalled func() uint64
EpochStartBlockRoundCalled func() uint64

ProcessBuiltInFunctionCalled func(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
GetBuiltinFunctionNamesCalled func() vmcommon.FunctionNames
GetAllStateCalled func(address []byte) (map[string][]byte, error)
Expand Down Expand Up @@ -153,6 +158,38 @@ func (b *BlockchainHookStub) CurrentEpoch() uint32 {
return 0
}

// RoundTime mocked method
func (b *BlockchainHookStub) RoundTime() uint64 {
if b.RoundTimeCalled != nil {
return b.RoundTimeCalled()
}
return 0
}

// EpochStartBlockTimeStamp mocked method
func (b *BlockchainHookStub) EpochStartBlockTimeStamp() uint64 {
if b.EpochStartBlockTimeStampCalled != nil {
return b.EpochStartBlockTimeStampCalled()
}
return 0
}

// EpochStartBlockNonce mocked method
func (b *BlockchainHookStub) EpochStartBlockNonce() uint64 {
if b.EpochStartBlockNonceCalled != nil {
return b.EpochStartBlockNonceCalled()
}
return 0
}

// EpochStartBlockRound VMHooks implementation.
func (b *BlockchainHookStub) EpochStartBlockRound() uint64 {
if b.EpochStartBlockRoundCalled != nil {
return b.EpochStartBlockRoundCalled()
}
return 0
}

// ProcessBuiltInFunction mocked method
func (b *BlockchainHookStub) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) {
if b.ProcessBuiltInFunctionCalled != nil {
Expand Down
20 changes: 20 additions & 0 deletions vmhost/mock/blockchainContextMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ func (b *BlockchainContextMock) CurrentTimeStamp() uint64 {
return 0
}

// RoundTime -
func (b *BlockchainContextMock) RoundTime() uint64 {
return 0
}

// EpochStartBlockTimeStamp -
func (b *BlockchainContextMock) EpochStartBlockTimeStamp() uint64 {
return 0
}

// EpochStartBlockNonce -
func (b *BlockchainContextMock) EpochStartBlockNonce() uint64 {
return 0
}

// EpochStartBlockRound -
func (b *BlockchainContextMock) EpochStartBlockRound() uint64 {
return 0
}

// CurrentRandomSeed -
func (b *BlockchainContextMock) CurrentRandomSeed() []byte {
return bytes.Repeat([]byte{1}, 32)
Expand Down

0 comments on commit 95d5c78

Please sign in to comment.