mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
implement osc client mock on msg_attest_machine
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
34182773dc
commit
f6c96094c6
1
go.mod
1
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/cosmos/go-bip39 v1.0.0
|
||||
github.com/cosmos/gogoproto v1.4.10
|
||||
github.com/cosmos/ibc-go/v7 v7.1.0
|
||||
github.com/crgimenes/go-osc v0.0.0-20230219003551-cc22b44f06a3
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/golang/protobuf v1.5.3
|
||||
github.com/gorilla/mux v1.8.0
|
||||
|
2
go.sum
2
go.sum
@ -368,6 +368,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
||||
github.com/creachadair/taskgroup v0.4.2 h1:jsBLdAJE42asreGss2xZGZ8fJra7WtwnHWeJFxv2Li8=
|
||||
github.com/creachadair/taskgroup v0.4.2/go.mod h1:qiXUOSrbwAY3u0JPGTzObbE3yf9hcXHDKBZ2ZjpCbgM=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/crgimenes/go-osc v0.0.0-20230219003551-cc22b44f06a3 h1:ffNeIlr2uX5jgPWlJq3pveSl9a3B6lftpuX978PMzk8=
|
||||
github.com/crgimenes/go-osc v0.0.0-20230219003551-cc22b44f06a3/go.mod h1:VgRiOtg6gFJfgCY2fMvfyORGwDM3EQ7Z9s/aO0k6cu8=
|
||||
github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0=
|
||||
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
|
||||
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
|
||||
|
@ -15,7 +15,10 @@ import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
machinetestutils "planetmint-go/x/machine/testutil"
|
||||
)
|
||||
|
||||
func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
@ -43,6 +46,10 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
memStoreKey,
|
||||
"MachineParams",
|
||||
)
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
oscMockClient := machinetestutils.NewMockClient(ctrl)
|
||||
|
||||
k := keeper.NewKeeper(
|
||||
cdc,
|
||||
storeKey,
|
||||
@ -51,6 +58,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
issuerLiquidIndexStoreKey,
|
||||
memStoreKey,
|
||||
paramsSubspace,
|
||||
oscMockClient,
|
||||
)
|
||||
|
||||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/crgimenes/go-osc"
|
||||
|
||||
"planetmint-go/x/machine/types"
|
||||
)
|
||||
@ -21,6 +22,7 @@ type (
|
||||
issuerLiquidIndexStoreKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
paramstore paramtypes.Subspace
|
||||
oscClient osc.Client
|
||||
}
|
||||
)
|
||||
|
||||
@ -32,7 +34,7 @@ func NewKeeper(
|
||||
issuerLiquidIndexStoreKey,
|
||||
memKey storetypes.StoreKey,
|
||||
ps paramtypes.Subspace,
|
||||
|
||||
oscClient osc.Client,
|
||||
) *Keeper {
|
||||
// set KeyTable if it has not already been set
|
||||
if !ps.HasKeyTable() {
|
||||
@ -47,6 +49,7 @@ func NewKeeper(
|
||||
issuerLiquidIndexStoreKey: issuerLiquidIndexStoreKey,
|
||||
memKey: memKey,
|
||||
paramstore: ps,
|
||||
oscClient: oscClient,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/crgimenes/go-osc"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -21,7 +22,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
||||
}
|
||||
|
||||
if msg.Machine.Reissue {
|
||||
k.Logger(ctx).Info("TODO Implement handle on reissue == true")
|
||||
k.reissueMachineNFT(msg.Machine)
|
||||
}
|
||||
|
||||
k.StoreMachine(ctx, *msg.Machine)
|
||||
@ -38,3 +39,12 @@ func validateIssuerLiquid(issuerLiquid string) bool {
|
||||
isValidLiquidKey := xpubKeyLiquid.IsForNet(&chaincfg.MainNetParams)
|
||||
return isValidLiquidKey
|
||||
}
|
||||
|
||||
func (k msgServer) reissueMachineNFT(machine *types.Machine) {
|
||||
// client := osc.NewClient("localhost", 8765)
|
||||
msg := osc.NewMessage("/osc/address")
|
||||
msg.Append(int32(111))
|
||||
msg.Append(true)
|
||||
msg.Append("hello")
|
||||
k.oscClient.Send(msg)
|
||||
}
|
||||
|
8
x/machine/testutil/osc_client_interface.go
Normal file
8
x/machine/testutil/osc_client_interface.go
Normal file
@ -0,0 +1,8 @@
|
||||
package testutil
|
||||
|
||||
import "github.com/crgimenes/go-osc"
|
||||
|
||||
type Client interface {
|
||||
Send(packet osc.Packet) error
|
||||
SetLocalAddr(ip string, port int) error
|
||||
}
|
63
x/machine/testutil/osc_client_mock.go
Normal file
63
x/machine/testutil/osc_client_mock.go
Normal file
@ -0,0 +1,63 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: x/machine/testutil/osc_client_interface.go
|
||||
|
||||
// Package testutil is a generated GoMock package.
|
||||
package testutil
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
osc "github.com/crgimenes/go-osc"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockClient is a mock of Client interface.
|
||||
type MockClient struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockClientMockRecorder
|
||||
}
|
||||
|
||||
// MockClientMockRecorder is the mock recorder for MockClient.
|
||||
type MockClientMockRecorder struct {
|
||||
mock *MockClient
|
||||
}
|
||||
|
||||
// NewMockClient creates a new mock instance.
|
||||
func NewMockClient(ctrl *gomock.Controller) *MockClient {
|
||||
mock := &MockClient{ctrl: ctrl}
|
||||
mock.recorder = &MockClientMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockClient) EXPECT() *MockClientMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Send mocks base method.
|
||||
func (m *MockClient) Send(packet osc.Packet) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Send", packet)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Send indicates an expected call of Send.
|
||||
func (mr *MockClientMockRecorder) Send(packet interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockClient)(nil).Send), packet)
|
||||
}
|
||||
|
||||
// SetLocalAddr mocks base method.
|
||||
func (m *MockClient) SetLocalAddr(ip string, port int) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetLocalAddr", ip, port)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetLocalAddr indicates an expected call of SetLocalAddr.
|
||||
func (mr *MockClientMockRecorder) SetLocalAddr(ip, port interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLocalAddr", reflect.TypeOf((*MockClient)(nil).SetLocalAddr), ip, port)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user