github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/keeper/wasmtesting/gas_register.go (about)

     1  package wasmtesting
     2  
     3  import (
     4  	wasmvmtypes "github.com/CosmWasm/wasmvm/types"
     5  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     6  )
     7  
     8  // MockGasRegister mock that implements keeper.GasRegister
     9  type MockGasRegister struct {
    10  	CompileCostFn             func(byteLength int) sdk.Gas
    11  	NewContractInstanceCostFn func(pinned bool, msgLen int) sdk.Gas
    12  	InstantiateContractCostFn func(pinned bool, msgLen int) sdk.Gas
    13  	ReplyCostFn               func(pinned bool, reply wasmvmtypes.Reply) sdk.Gas
    14  	EventCostsFn              func(evts []wasmvmtypes.EventAttribute) sdk.Gas
    15  	ToWasmVMGasFn             func(source sdk.Gas) uint64
    16  	FromWasmVMGasFn           func(source uint64) sdk.Gas
    17  }
    18  
    19  func (m MockGasRegister) NewContractInstanceCosts(pinned bool, msgLen int) sdk.Gas {
    20  	if m.NewContractInstanceCostFn == nil {
    21  		panic("not expected to be called")
    22  	}
    23  	return m.NewContractInstanceCostFn(pinned, msgLen)
    24  }
    25  
    26  func (m MockGasRegister) CompileCosts(byteLength int) sdk.Gas {
    27  	if m.CompileCostFn == nil {
    28  		panic("not expected to be called")
    29  	}
    30  	return m.CompileCostFn(byteLength)
    31  }
    32  
    33  func (m MockGasRegister) InstantiateContractCosts(pinned bool, msgLen int) sdk.Gas {
    34  	if m.InstantiateContractCostFn == nil {
    35  		panic("not expected to be called")
    36  	}
    37  	return m.InstantiateContractCostFn(pinned, msgLen)
    38  }
    39  
    40  func (m MockGasRegister) ReplyCosts(pinned bool, reply wasmvmtypes.Reply) sdk.Gas {
    41  	if m.ReplyCostFn == nil {
    42  		panic("not expected to be called")
    43  	}
    44  	return m.ReplyCostFn(pinned, reply)
    45  }
    46  
    47  func (m MockGasRegister) EventCosts(evts []wasmvmtypes.EventAttribute, events wasmvmtypes.Events) sdk.Gas {
    48  	if m.EventCostsFn == nil {
    49  		panic("not expected to be called")
    50  	}
    51  	return m.EventCostsFn(evts)
    52  }
    53  
    54  func (m MockGasRegister) ToWasmVMGas(source sdk.Gas) uint64 {
    55  	if m.ToWasmVMGasFn == nil {
    56  		panic("not expected to be called")
    57  	}
    58  	return m.ToWasmVMGasFn(source)
    59  }
    60  
    61  func (m MockGasRegister) FromWasmVMGas(source uint64) sdk.Gas {
    62  	if m.FromWasmVMGasFn == nil {
    63  		panic("not expected to be called")
    64  	}
    65  	return m.FromWasmVMGasFn(source)
    66  }