From 5a8a555d97cad8cb44a903dc9c7af6df17114c67 Mon Sep 17 00:00:00 2001 From: Max Levitskiy Date: Mon, 26 Jun 2023 11:46:10 +0200 Subject: [PATCH 1/3] State and chain mocks added --- contract/pkg/mock/substrate_chain.go | 171 ++++++++++ contract/pkg/mock/substrate_state.go | 486 +++++++++++++++++++++++++++ 2 files changed, 657 insertions(+) create mode 100644 contract/pkg/mock/substrate_chain.go create mode 100644 contract/pkg/mock/substrate_state.go diff --git a/contract/pkg/mock/substrate_chain.go b/contract/pkg/mock/substrate_chain.go new file mode 100644 index 0000000..b764704 --- /dev/null +++ b/contract/pkg/mock/substrate_chain.go @@ -0,0 +1,171 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/centrifuge/go-substrate-rpc-client/v4/rpc/chain (interfaces: Chain) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + chain "github.com/centrifuge/go-substrate-rpc-client/v4/rpc/chain" + types "github.com/centrifuge/go-substrate-rpc-client/v4/types" + gomock "github.com/golang/mock/gomock" +) + +// MockChain is a mock of Chain interface. +type MockChain struct { + ctrl *gomock.Controller + recorder *MockChainMockRecorder +} + +// MockChainMockRecorder is the mock recorder for MockChain. +type MockChainMockRecorder struct { + mock *MockChain +} + +// NewMockChain creates a new mock instance. +func NewMockChain(ctrl *gomock.Controller) *MockChain { + mock := &MockChain{ctrl: ctrl} + mock.recorder = &MockChainMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChain) EXPECT() *MockChainMockRecorder { + return m.recorder +} + +// GetBlock mocks base method. +func (m *MockChain) GetBlock(arg0 types.Hash) (*types.SignedBlock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlock", arg0) + ret0, _ := ret[0].(*types.SignedBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlock indicates an expected call of GetBlock. +func (mr *MockChainMockRecorder) GetBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlock", reflect.TypeOf((*MockChain)(nil).GetBlock), arg0) +} + +// GetBlockHash mocks base method. +func (m *MockChain) GetBlockHash(arg0 uint64) (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockHash", arg0) + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockHash indicates an expected call of GetBlockHash. +func (mr *MockChainMockRecorder) GetBlockHash(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockHash", reflect.TypeOf((*MockChain)(nil).GetBlockHash), arg0) +} + +// GetBlockHashLatest mocks base method. +func (m *MockChain) GetBlockHashLatest() (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockHashLatest") + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockHashLatest indicates an expected call of GetBlockHashLatest. +func (mr *MockChainMockRecorder) GetBlockHashLatest() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockHashLatest", reflect.TypeOf((*MockChain)(nil).GetBlockHashLatest)) +} + +// GetBlockLatest mocks base method. +func (m *MockChain) GetBlockLatest() (*types.SignedBlock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockLatest") + ret0, _ := ret[0].(*types.SignedBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBlockLatest indicates an expected call of GetBlockLatest. +func (mr *MockChainMockRecorder) GetBlockLatest() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockLatest", reflect.TypeOf((*MockChain)(nil).GetBlockLatest)) +} + +// GetFinalizedHead mocks base method. +func (m *MockChain) GetFinalizedHead() (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFinalizedHead") + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFinalizedHead indicates an expected call of GetFinalizedHead. +func (mr *MockChainMockRecorder) GetFinalizedHead() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFinalizedHead", reflect.TypeOf((*MockChain)(nil).GetFinalizedHead)) +} + +// GetHeader mocks base method. +func (m *MockChain) GetHeader(arg0 types.Hash) (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHeader", arg0) + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHeader indicates an expected call of GetHeader. +func (mr *MockChainMockRecorder) GetHeader(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHeader", reflect.TypeOf((*MockChain)(nil).GetHeader), arg0) +} + +// GetHeaderLatest mocks base method. +func (m *MockChain) GetHeaderLatest() (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHeaderLatest") + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHeaderLatest indicates an expected call of GetHeaderLatest. +func (mr *MockChainMockRecorder) GetHeaderLatest() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHeaderLatest", reflect.TypeOf((*MockChain)(nil).GetHeaderLatest)) +} + +// SubscribeFinalizedHeads mocks base method. +func (m *MockChain) SubscribeFinalizedHeads() (*chain.FinalizedHeadsSubscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeFinalizedHeads") + ret0, _ := ret[0].(*chain.FinalizedHeadsSubscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubscribeFinalizedHeads indicates an expected call of SubscribeFinalizedHeads. +func (mr *MockChainMockRecorder) SubscribeFinalizedHeads() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeFinalizedHeads", reflect.TypeOf((*MockChain)(nil).SubscribeFinalizedHeads)) +} + +// SubscribeNewHeads mocks base method. +func (m *MockChain) SubscribeNewHeads() (*chain.NewHeadsSubscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeNewHeads") + ret0, _ := ret[0].(*chain.NewHeadsSubscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubscribeNewHeads indicates an expected call of SubscribeNewHeads. +func (mr *MockChainMockRecorder) SubscribeNewHeads() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeNewHeads", reflect.TypeOf((*MockChain)(nil).SubscribeNewHeads)) +} diff --git a/contract/pkg/mock/substrate_state.go b/contract/pkg/mock/substrate_state.go new file mode 100644 index 0000000..36dd724 --- /dev/null +++ b/contract/pkg/mock/substrate_state.go @@ -0,0 +1,486 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/centrifuge/go-substrate-rpc-client/v4/rpc/state (interfaces: State) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + state "github.com/centrifuge/go-substrate-rpc-client/v4/rpc/state" + types "github.com/centrifuge/go-substrate-rpc-client/v4/types" + gomock "github.com/golang/mock/gomock" +) + +// MockState is a mock of State interface. +type MockState struct { + ctrl *gomock.Controller + recorder *MockStateMockRecorder +} + +// MockStateMockRecorder is the mock recorder for MockState. +type MockStateMockRecorder struct { + mock *MockState +} + +// NewMockState creates a new mock instance. +func NewMockState(ctrl *gomock.Controller) *MockState { + mock := &MockState{ctrl: ctrl} + mock.recorder = &MockStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockState) EXPECT() *MockStateMockRecorder { + return m.recorder +} + +// GetChildKeys mocks base method. +func (m *MockState) GetChildKeys(arg0, arg1 types.StorageKey, arg2 types.Hash) ([]types.StorageKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildKeys", arg0, arg1, arg2) + ret0, _ := ret[0].([]types.StorageKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildKeys indicates an expected call of GetChildKeys. +func (mr *MockStateMockRecorder) GetChildKeys(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildKeys", reflect.TypeOf((*MockState)(nil).GetChildKeys), arg0, arg1, arg2) +} + +// GetChildKeysLatest mocks base method. +func (m *MockState) GetChildKeysLatest(arg0, arg1 types.StorageKey) ([]types.StorageKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildKeysLatest", arg0, arg1) + ret0, _ := ret[0].([]types.StorageKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildKeysLatest indicates an expected call of GetChildKeysLatest. +func (mr *MockStateMockRecorder) GetChildKeysLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildKeysLatest", reflect.TypeOf((*MockState)(nil).GetChildKeysLatest), arg0, arg1) +} + +// GetChildStorage mocks base method. +func (m *MockState) GetChildStorage(arg0, arg1 types.StorageKey, arg2 interface{}, arg3 types.Hash) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorage", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorage indicates an expected call of GetChildStorage. +func (mr *MockStateMockRecorder) GetChildStorage(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorage", reflect.TypeOf((*MockState)(nil).GetChildStorage), arg0, arg1, arg2, arg3) +} + +// GetChildStorageHash mocks base method. +func (m *MockState) GetChildStorageHash(arg0, arg1 types.StorageKey, arg2 types.Hash) (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageHash", arg0, arg1, arg2) + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageHash indicates an expected call of GetChildStorageHash. +func (mr *MockStateMockRecorder) GetChildStorageHash(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageHash", reflect.TypeOf((*MockState)(nil).GetChildStorageHash), arg0, arg1, arg2) +} + +// GetChildStorageHashLatest mocks base method. +func (m *MockState) GetChildStorageHashLatest(arg0, arg1 types.StorageKey) (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageHashLatest", arg0, arg1) + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageHashLatest indicates an expected call of GetChildStorageHashLatest. +func (mr *MockStateMockRecorder) GetChildStorageHashLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageHashLatest", reflect.TypeOf((*MockState)(nil).GetChildStorageHashLatest), arg0, arg1) +} + +// GetChildStorageLatest mocks base method. +func (m *MockState) GetChildStorageLatest(arg0, arg1 types.StorageKey, arg2 interface{}) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageLatest", arg0, arg1, arg2) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageLatest indicates an expected call of GetChildStorageLatest. +func (mr *MockStateMockRecorder) GetChildStorageLatest(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageLatest", reflect.TypeOf((*MockState)(nil).GetChildStorageLatest), arg0, arg1, arg2) +} + +// GetChildStorageRaw mocks base method. +func (m *MockState) GetChildStorageRaw(arg0, arg1 types.StorageKey, arg2 types.Hash) (*types.StorageDataRaw, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageRaw", arg0, arg1, arg2) + ret0, _ := ret[0].(*types.StorageDataRaw) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageRaw indicates an expected call of GetChildStorageRaw. +func (mr *MockStateMockRecorder) GetChildStorageRaw(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageRaw", reflect.TypeOf((*MockState)(nil).GetChildStorageRaw), arg0, arg1, arg2) +} + +// GetChildStorageRawLatest mocks base method. +func (m *MockState) GetChildStorageRawLatest(arg0, arg1 types.StorageKey) (*types.StorageDataRaw, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageRawLatest", arg0, arg1) + ret0, _ := ret[0].(*types.StorageDataRaw) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageRawLatest indicates an expected call of GetChildStorageRawLatest. +func (mr *MockStateMockRecorder) GetChildStorageRawLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageRawLatest", reflect.TypeOf((*MockState)(nil).GetChildStorageRawLatest), arg0, arg1) +} + +// GetChildStorageSize mocks base method. +func (m *MockState) GetChildStorageSize(arg0, arg1 types.StorageKey, arg2 types.Hash) (types.U64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageSize", arg0, arg1, arg2) + ret0, _ := ret[0].(types.U64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageSize indicates an expected call of GetChildStorageSize. +func (mr *MockStateMockRecorder) GetChildStorageSize(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageSize", reflect.TypeOf((*MockState)(nil).GetChildStorageSize), arg0, arg1, arg2) +} + +// GetChildStorageSizeLatest mocks base method. +func (m *MockState) GetChildStorageSizeLatest(arg0, arg1 types.StorageKey) (types.U64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChildStorageSizeLatest", arg0, arg1) + ret0, _ := ret[0].(types.U64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChildStorageSizeLatest indicates an expected call of GetChildStorageSizeLatest. +func (mr *MockStateMockRecorder) GetChildStorageSizeLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChildStorageSizeLatest", reflect.TypeOf((*MockState)(nil).GetChildStorageSizeLatest), arg0, arg1) +} + +// GetKeys mocks base method. +func (m *MockState) GetKeys(arg0 types.StorageKey, arg1 types.Hash) ([]types.StorageKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKeys", arg0, arg1) + ret0, _ := ret[0].([]types.StorageKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetKeys indicates an expected call of GetKeys. +func (mr *MockStateMockRecorder) GetKeys(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeys", reflect.TypeOf((*MockState)(nil).GetKeys), arg0, arg1) +} + +// GetKeysLatest mocks base method. +func (m *MockState) GetKeysLatest(arg0 types.StorageKey) ([]types.StorageKey, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKeysLatest", arg0) + ret0, _ := ret[0].([]types.StorageKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetKeysLatest indicates an expected call of GetKeysLatest. +func (mr *MockStateMockRecorder) GetKeysLatest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeysLatest", reflect.TypeOf((*MockState)(nil).GetKeysLatest), arg0) +} + +// GetMetadata mocks base method. +func (m *MockState) GetMetadata(arg0 types.Hash) (*types.Metadata, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMetadata", arg0) + ret0, _ := ret[0].(*types.Metadata) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMetadata indicates an expected call of GetMetadata. +func (mr *MockStateMockRecorder) GetMetadata(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetadata", reflect.TypeOf((*MockState)(nil).GetMetadata), arg0) +} + +// GetMetadataLatest mocks base method. +func (m *MockState) GetMetadataLatest() (*types.Metadata, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMetadataLatest") + ret0, _ := ret[0].(*types.Metadata) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMetadataLatest indicates an expected call of GetMetadataLatest. +func (mr *MockStateMockRecorder) GetMetadataLatest() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetadataLatest", reflect.TypeOf((*MockState)(nil).GetMetadataLatest)) +} + +// GetRuntimeVersion mocks base method. +func (m *MockState) GetRuntimeVersion(arg0 types.Hash) (*types.RuntimeVersion, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuntimeVersion", arg0) + ret0, _ := ret[0].(*types.RuntimeVersion) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRuntimeVersion indicates an expected call of GetRuntimeVersion. +func (mr *MockStateMockRecorder) GetRuntimeVersion(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuntimeVersion", reflect.TypeOf((*MockState)(nil).GetRuntimeVersion), arg0) +} + +// GetRuntimeVersionLatest mocks base method. +func (m *MockState) GetRuntimeVersionLatest() (*types.RuntimeVersion, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuntimeVersionLatest") + ret0, _ := ret[0].(*types.RuntimeVersion) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRuntimeVersionLatest indicates an expected call of GetRuntimeVersionLatest. +func (mr *MockStateMockRecorder) GetRuntimeVersionLatest() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuntimeVersionLatest", reflect.TypeOf((*MockState)(nil).GetRuntimeVersionLatest)) +} + +// GetStorage mocks base method. +func (m *MockState) GetStorage(arg0 types.StorageKey, arg1 interface{}, arg2 types.Hash) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorage", arg0, arg1, arg2) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorage indicates an expected call of GetStorage. +func (mr *MockStateMockRecorder) GetStorage(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorage", reflect.TypeOf((*MockState)(nil).GetStorage), arg0, arg1, arg2) +} + +// GetStorageHash mocks base method. +func (m *MockState) GetStorageHash(arg0 types.StorageKey, arg1 types.Hash) (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageHash", arg0, arg1) + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageHash indicates an expected call of GetStorageHash. +func (mr *MockStateMockRecorder) GetStorageHash(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageHash", reflect.TypeOf((*MockState)(nil).GetStorageHash), arg0, arg1) +} + +// GetStorageHashLatest mocks base method. +func (m *MockState) GetStorageHashLatest(arg0 types.StorageKey) (types.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageHashLatest", arg0) + ret0, _ := ret[0].(types.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageHashLatest indicates an expected call of GetStorageHashLatest. +func (mr *MockStateMockRecorder) GetStorageHashLatest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageHashLatest", reflect.TypeOf((*MockState)(nil).GetStorageHashLatest), arg0) +} + +// GetStorageLatest mocks base method. +func (m *MockState) GetStorageLatest(arg0 types.StorageKey, arg1 interface{}) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageLatest", arg0, arg1) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageLatest indicates an expected call of GetStorageLatest. +func (mr *MockStateMockRecorder) GetStorageLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageLatest", reflect.TypeOf((*MockState)(nil).GetStorageLatest), arg0, arg1) +} + +// GetStorageRaw mocks base method. +func (m *MockState) GetStorageRaw(arg0 types.StorageKey, arg1 types.Hash) (*types.StorageDataRaw, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageRaw", arg0, arg1) + ret0, _ := ret[0].(*types.StorageDataRaw) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageRaw indicates an expected call of GetStorageRaw. +func (mr *MockStateMockRecorder) GetStorageRaw(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageRaw", reflect.TypeOf((*MockState)(nil).GetStorageRaw), arg0, arg1) +} + +// GetStorageRawLatest mocks base method. +func (m *MockState) GetStorageRawLatest(arg0 types.StorageKey) (*types.StorageDataRaw, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageRawLatest", arg0) + ret0, _ := ret[0].(*types.StorageDataRaw) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageRawLatest indicates an expected call of GetStorageRawLatest. +func (mr *MockStateMockRecorder) GetStorageRawLatest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageRawLatest", reflect.TypeOf((*MockState)(nil).GetStorageRawLatest), arg0) +} + +// GetStorageSize mocks base method. +func (m *MockState) GetStorageSize(arg0 types.StorageKey, arg1 types.Hash) (types.U64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageSize", arg0, arg1) + ret0, _ := ret[0].(types.U64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageSize indicates an expected call of GetStorageSize. +func (mr *MockStateMockRecorder) GetStorageSize(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageSize", reflect.TypeOf((*MockState)(nil).GetStorageSize), arg0, arg1) +} + +// GetStorageSizeLatest mocks base method. +func (m *MockState) GetStorageSizeLatest(arg0 types.StorageKey) (types.U64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStorageSizeLatest", arg0) + ret0, _ := ret[0].(types.U64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetStorageSizeLatest indicates an expected call of GetStorageSizeLatest. +func (mr *MockStateMockRecorder) GetStorageSizeLatest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageSizeLatest", reflect.TypeOf((*MockState)(nil).GetStorageSizeLatest), arg0) +} + +// QueryStorage mocks base method. +func (m *MockState) QueryStorage(arg0 []types.StorageKey, arg1, arg2 types.Hash) ([]types.StorageChangeSet, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryStorage", arg0, arg1, arg2) + ret0, _ := ret[0].([]types.StorageChangeSet) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryStorage indicates an expected call of QueryStorage. +func (mr *MockStateMockRecorder) QueryStorage(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryStorage", reflect.TypeOf((*MockState)(nil).QueryStorage), arg0, arg1, arg2) +} + +// QueryStorageAt mocks base method. +func (m *MockState) QueryStorageAt(arg0 []types.StorageKey, arg1 types.Hash) ([]types.StorageChangeSet, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryStorageAt", arg0, arg1) + ret0, _ := ret[0].([]types.StorageChangeSet) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryStorageAt indicates an expected call of QueryStorageAt. +func (mr *MockStateMockRecorder) QueryStorageAt(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryStorageAt", reflect.TypeOf((*MockState)(nil).QueryStorageAt), arg0, arg1) +} + +// QueryStorageAtLatest mocks base method. +func (m *MockState) QueryStorageAtLatest(arg0 []types.StorageKey) ([]types.StorageChangeSet, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryStorageAtLatest", arg0) + ret0, _ := ret[0].([]types.StorageChangeSet) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryStorageAtLatest indicates an expected call of QueryStorageAtLatest. +func (mr *MockStateMockRecorder) QueryStorageAtLatest(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryStorageAtLatest", reflect.TypeOf((*MockState)(nil).QueryStorageAtLatest), arg0) +} + +// QueryStorageLatest mocks base method. +func (m *MockState) QueryStorageLatest(arg0 []types.StorageKey, arg1 types.Hash) ([]types.StorageChangeSet, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryStorageLatest", arg0, arg1) + ret0, _ := ret[0].([]types.StorageChangeSet) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryStorageLatest indicates an expected call of QueryStorageLatest. +func (mr *MockStateMockRecorder) QueryStorageLatest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryStorageLatest", reflect.TypeOf((*MockState)(nil).QueryStorageLatest), arg0, arg1) +} + +// SubscribeRuntimeVersion mocks base method. +func (m *MockState) SubscribeRuntimeVersion() (*state.RuntimeVersionSubscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeRuntimeVersion") + ret0, _ := ret[0].(*state.RuntimeVersionSubscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubscribeRuntimeVersion indicates an expected call of SubscribeRuntimeVersion. +func (mr *MockStateMockRecorder) SubscribeRuntimeVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeRuntimeVersion", reflect.TypeOf((*MockState)(nil).SubscribeRuntimeVersion)) +} + +// SubscribeStorageRaw mocks base method. +func (m *MockState) SubscribeStorageRaw(arg0 []types.StorageKey) (*state.StorageSubscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeStorageRaw", arg0) + ret0, _ := ret[0].(*state.StorageSubscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubscribeStorageRaw indicates an expected call of SubscribeStorageRaw. +func (mr *MockStateMockRecorder) SubscribeStorageRaw(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeStorageRaw", reflect.TypeOf((*MockState)(nil).SubscribeStorageRaw), arg0) +} From 1327c085f40c0d1007eb0c57558272559309b241 Mon Sep 17 00:00:00 2001 From: Max Levitskiy Date: Mon, 26 Jun 2023 11:45:47 +0200 Subject: [PATCH 2/3] Move types and utils from pkg to subpackages to avoid cyclic dependencies --- .../actcapture/activity_capture_contract.go | 11 ++- contract/pkg/bucket/ddc_bucket_contract.go | 16 +-- .../pkg/cache/ddc_bucket_contract_cache.go | 4 +- .../cache/ddc_bucket_contract_cache_test.go | 4 +- contract/pkg/client.go | 99 ++++++------------- contract/pkg/mock/ddc_bucket_contract_mock.go | 7 +- contract/pkg/sdktypes/types.go | 61 ++++++++++++ contract/pkg/{ => utils}/utils.go | 4 +- contract/pkg/{ => utils}/utils_test.go | 2 +- test/setup_test.go | 19 ++-- 10 files changed, 124 insertions(+), 103 deletions(-) create mode 100644 contract/pkg/sdktypes/types.go rename contract/pkg/{ => utils}/utils.go (96%) rename contract/pkg/{ => utils}/utils_test.go (96%) diff --git a/contract/pkg/actcapture/activity_capture_contract.go b/contract/pkg/actcapture/activity_capture_contract.go index b42f816..20a748f 100644 --- a/contract/pkg/actcapture/activity_capture_contract.go +++ b/contract/pkg/actcapture/activity_capture_contract.go @@ -6,7 +6,8 @@ import ( "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/centrifuge/go-substrate-rpc-client/v4/types" "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" log "github.com/sirupsen/logrus" "math/big" ) @@ -26,7 +27,7 @@ type ( } activityCaptureContract struct { - client pkg.BlockchainClient + client sdktypes.BlockchainClient account types.AccountID keyringPair signature.KeyringPair contractAddress types.AccountID @@ -37,7 +38,7 @@ type ( } ) -func CreateActivityCaptureContract(client pkg.BlockchainClient, contractAddressSS58 string, secret string) ActivityCaptureContract { +func CreateActivityCaptureContract(client sdktypes.BlockchainClient, contractAddressSS58 string, secret string) ActivityCaptureContract { keyringPair, err := signature.KeyringPairFromSecret(secret, 42) if err != nil { log.WithError(err).Fatal("Can't initialize keyring pair for activity capture contract") @@ -63,7 +64,7 @@ func CreateActivityCaptureContract(client pkg.BlockchainClient, contractAddressS log.WithError(err).WithField("method", getEraSettings).Fatal("Can't decode method getEraSettingsMethod") } - contractAddress, err := pkg.DecodeAccountIDFromSS58(contractAddressSS58) + contractAddress, err := utils.DecodeAccountIDFromSS58(contractAddressSS58) if err != nil { log.WithError(err).WithField("contractAddressSS58", contractAddressSS58).Fatal("Can't decode contract address SS58") } @@ -101,7 +102,7 @@ func (a *activityCaptureContract) SetCommit(ctx context.Context, hash []byte, ga From := types.U64(from) To := types.U64(to) - call := pkg.ContractCall{ + call := sdktypes.ContractCall{ ContractAddress: a.contractAddress, ContractAddressSS58: a.contractAddressSS58, From: a.keyringPair, diff --git a/contract/pkg/bucket/ddc_bucket_contract.go b/contract/pkg/bucket/ddc_bucket_contract.go index eaf8ab8..2bb1cae 100644 --- a/contract/pkg/bucket/ddc_bucket_contract.go +++ b/contract/pkg/bucket/ddc_bucket_contract.go @@ -4,12 +4,12 @@ import ( _ "embed" "encoding/hex" "errors" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" "reflect" "time" "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" log "github.com/sirupsen/logrus" ) @@ -50,11 +50,11 @@ type ( CDNNodeGet(nodeId uint32) (*CDNNodeStatus, error) AccountGet(account types.AccountID) (*Account, error) AddContractEventHandler(event string, handler func(interface{})) error - GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry + GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry } ddcBucketContract struct { - contract pkg.BlockchainClient + contract sdktypes.BlockchainClient lastAccessTime time.Time contractAddressSS58 string keyringPair signature.KeyringPair @@ -64,7 +64,7 @@ type ( cdnClusterGetMethodId []byte cdnNodeGetMethodId []byte accountGetMethodId []byte - eventDispatcher map[types.Hash]pkg.ContractEventDispatchEntry + eventDispatcher map[types.Hash]sdktypes.ContractEventDispatchEntry } ) @@ -85,7 +85,7 @@ var eventDispatchTable = map[string]reflect.Type{ GrantPermissionEventId: reflect.TypeOf(GrantPermissionEvent{}), RevokePermissionEventId: reflect.TypeOf(RevokePermissionEvent{})} -func CreateDdcBucketContract(client pkg.BlockchainClient, contractAddressSS58 string) DdcBucketContract { +func CreateDdcBucketContract(client sdktypes.BlockchainClient, contractAddressSS58 string) DdcBucketContract { bucketGetMethodId, err := hex.DecodeString(bucketGetMethod) if err != nil { log.WithError(err).WithField("method", bucketGetMethod).Fatal("Can't decode method bucketGetMethod") @@ -116,12 +116,12 @@ func CreateDdcBucketContract(client pkg.BlockchainClient, contractAddressSS58 st log.WithError(err).WithField("method", accountGetMethod).Fatal("Can't decode method accountGetMethod") } - eventDispatcher := make(map[types.Hash]pkg.ContractEventDispatchEntry) + eventDispatcher := make(map[types.Hash]sdktypes.ContractEventDispatchEntry) for k, v := range eventDispatchTable { if key, err := types.NewHashFromHexString(k); err != nil { log.WithError(err).WithField("hash", k).Fatalf("Bad event hash for event %s", v.Name()) } else { - eventDispatcher[key] = pkg.ContractEventDispatchEntry{ArgumentType: v} + eventDispatcher[key] = sdktypes.ContractEventDispatchEntry{ArgumentType: v} } } @@ -224,6 +224,6 @@ func (d *ddcBucketContract) GetLastAccessTime() time.Time { return d.lastAccessTime } -func (d *ddcBucketContract) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry { +func (d *ddcBucketContract) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry { return d.eventDispatcher } diff --git a/contract/pkg/cache/ddc_bucket_contract_cache.go b/contract/pkg/cache/ddc_bucket_contract_cache.go index 987ddcd..5e6c8c0 100644 --- a/contract/pkg/cache/ddc_bucket_contract_cache.go +++ b/contract/pkg/cache/ddc_bucket_contract_cache.go @@ -2,11 +2,11 @@ package cache import ( "encoding/hex" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" "strconv" "time" "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket" "github.com/golang/groupcache/singleflight" "github.com/patrickmn/go-cache" @@ -184,7 +184,7 @@ func (d *ddcBucketContractCached) AddContractEventHandler(event string, handler return d.ddcBucketContract.AddContractEventHandler(event, handler) } -func (d *ddcBucketContractCached) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry { +func (d *ddcBucketContractCached) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry { return d.ddcBucketContract.GetEventDispatcher() } diff --git a/contract/pkg/cache/ddc_bucket_contract_cache_test.go b/contract/pkg/cache/ddc_bucket_contract_cache_test.go index c385b8e..ee439b7 100644 --- a/contract/pkg/cache/ddc_bucket_contract_cache_test.go +++ b/contract/pkg/cache/ddc_bucket_contract_cache_test.go @@ -1,11 +1,11 @@ package cache import ( + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" "testing" "time" "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket" "github.com/patrickmn/go-cache" "github.com/stretchr/testify/assert" @@ -60,7 +60,7 @@ func (d *mockedDdcBucketContract) AddContractEventHandler(event string, handler return nil } -func (d *mockedDdcBucketContract) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry { +func (d *mockedDdcBucketContract) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry { return nil } diff --git a/contract/pkg/client.go b/contract/pkg/client.go index 490155c..45aaa82 100644 --- a/contract/pkg/client.go +++ b/contract/pkg/client.go @@ -3,6 +3,8 @@ package pkg import ( "bytes" "context" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" "os/signal" "reflect" "sync" @@ -22,69 +24,16 @@ const ( ) type ( - BlockchainClient interface { - CallToReadEncoded(contractAddressSS58 string, fromAddress string, method []byte, args ...interface{}) (string, error) - CallToExec(ctx context.Context, contractCall ContractCall) (types.Hash, error) - Deploy(ctx context.Context, deployCall DeployCall) (types.AccountID, error) - SetEventDispatcher(contractAddressSS58 string, dispatcher map[types.Hash]ContractEventDispatchEntry) error - } - blockchainClient struct { *gsrpc.SubstrateAPI eventContractAccount types.AccountID - eventDispatcher map[types.Hash]ContractEventDispatchEntry + eventDispatcher map[types.Hash]sdktypes.ContractEventDispatchEntry eventContextCancel context.CancelFunc connectMutex sync.Mutex } - - ContractCall struct { - ContractAddress types.AccountID - ContractAddressSS58 string - From signature.KeyringPair - Value float64 - GasLimit float64 - Method []byte - Args []interface{} - } - - DeployCall struct { - Code []byte - Salt []byte - From signature.KeyringPair - Value float64 - GasLimit float64 - Method []byte - Args []interface{} - } - - ContractEventDispatchEntry struct { - ArgumentType reflect.Type - Handler ContractEventHandler - } - - ContractEventHandler func(interface{}) - - Response struct { - DebugMessage string `json:"debugMessage"` - GasConsumed int `json:"gasConsumed"` - Result struct { - Ok struct { - Data string `json:"data"` - Flags int `json:"flags"` - } `json:"Ok"` - } `json:"result"` - } - - Request struct { - Origin string `json:"origin"` - Dest string `json:"dest"` - GasLimit uint `json:"gasLimit"` - InputData string `json:"inputData"` - Value int `json:"value"` - } ) -func CreateBlockchainClient(apiUrl string) BlockchainClient { +func CreateBlockchainClient(apiUrl string) sdktypes.BlockchainClient { substrateAPI, err := gsrpc.NewSubstrateAPI(apiUrl) if err != nil { log.WithError(err).WithField("apiUrl", apiUrl).Fatal("Can't connect to blockchainClient") @@ -95,8 +44,8 @@ func CreateBlockchainClient(apiUrl string) BlockchainClient { } } -func (b *blockchainClient) SetEventDispatcher(contractAddressSS58 string, dispatcher map[types.Hash]ContractEventDispatchEntry) error { - contract, err := DecodeAccountIDFromSS58(contractAddressSS58) +func (b *blockchainClient) SetEventDispatcher(contractAddressSS58 string, dispatcher map[types.Hash]sdktypes.ContractEventDispatchEntry) error { + contract, err := utils.DecodeAccountIDFromSS58(contractAddressSS58) if err != nil { return err } @@ -129,6 +78,7 @@ func (b *blockchainClient) listenContractEvents() error { b.eventContextCancel = cancel watchdog := time.NewTicker(time.Minute) eventArrived := true + var lastEventBlock types.BlockNumber go func() { defer sub.Unsubscribe() for { @@ -158,6 +108,13 @@ func (b *blockchainClient) listenContractEvents() error { break } eventArrived = true + block, err := b.RPC.Chain.GetBlock(evt.Block) + if err != nil { + log.WithError(err).Warn("Error fetching block") + break + } + lastEventBlock = block.Block.Header.Number + print(lastEventBlock) // parse all events for this block for _, chng := range evt.Changes { @@ -179,8 +136,8 @@ func (b *blockchainClient) listenContractEvents() error { } // Identify the event by matching one of its topics against known signatures. The topics are sorted so - // the the needed one may be in the arbitrary position. - var dispatchEntry ContractEventDispatchEntry + // the needed one may be in the arbitrary position. + var dispatchEntry sdktypes.ContractEventDispatchEntry found := false for _, topic := range e.Topics { dispatchEntry, found = b.eventDispatcher[topic] @@ -217,7 +174,7 @@ func (b *blockchainClient) listenContractEvents() error { } func (b *blockchainClient) CallToReadEncoded(contractAddressSS58 string, fromAddress string, method []byte, args ...interface{}) (string, error) { - data, err := GetContractData(method, args...) + data, err := utils.GetContractData(method, args...) if err != nil { return "", errors.Wrap(err, "getMessagesData") } @@ -230,27 +187,27 @@ func (b *blockchainClient) CallToReadEncoded(contractAddressSS58 string, fromAdd return res.Result.Ok.Data, nil } -func (b *blockchainClient) callToRead(contractAddressSS58 string, fromAddress string, data []byte) (Response, error) { - params := Request{ +func (b *blockchainClient) callToRead(contractAddressSS58 string, fromAddress string, data []byte) (sdktypes.Response, error) { + params := sdktypes.Request{ Origin: fromAddress, Dest: contractAddressSS58, GasLimit: 500_000_000_000, InputData: codec.HexEncodeToString(data), } - res, err := withRetryOnClosedNetwork(b, func() (Response, error) { - res := Response{} + res, err := withRetryOnClosedNetwork(b, func() (sdktypes.Response, error) { + res := sdktypes.Response{} return res, b.Client.Call(&res, "contracts_call", params) }) if err != nil { - return Response{}, errors.Wrap(err, "call") + return sdktypes.Response{}, errors.Wrap(err, "call") } return res, nil } -func (b *blockchainClient) CallToExec(ctx context.Context, contractCall ContractCall) (types.Hash, error) { - data, err := GetContractData(contractCall.Method, contractCall.Args...) +func (b *blockchainClient) CallToExec(ctx context.Context, contractCall sdktypes.ContractCall) (types.Hash, error) { + data, err := utils.GetContractData(contractCall.Method, contractCall.Args...) if err != nil { return types.Hash{}, err } @@ -285,13 +242,13 @@ func (b *blockchainClient) CallToExec(ctx context.Context, contractCall Contract return hash, err } -func (b *blockchainClient) Deploy(ctx context.Context, deployCall DeployCall) (types.AccountID, error) { +func (b *blockchainClient) Deploy(ctx context.Context, deployCall sdktypes.DeployCall) (types.AccountID, error) { deployer, err := types.NewAccountID(deployCall.From.PublicKey) if err != nil { return types.AccountID{}, err } - data, err := GetContractData(deployCall.Method, deployCall.Args...) + data, err := utils.GetContractData(deployCall.Method, deployCall.Args...) if err != nil { return types.AccountID{}, err } @@ -435,7 +392,7 @@ func (b *blockchainClient) submitAndWaitExtrinsic(ctx context.Context, extrinsic func withRetryOnClosedNetwork[T any](b *blockchainClient, f func() (T, error)) (T, error) { result, err := f() - if isClosedNetworkError(err) { + if utils.IsClosedNetworkError(err) { if b.reconnect() != nil { return result, err } @@ -449,7 +406,7 @@ func (b *blockchainClient) reconnect() error { b.connectMutex.Lock() defer b.connectMutex.Unlock() _, err := b.RPC.State.GetRuntimeVersionLatest() - if !isClosedNetworkError(err) { + if !utils.IsClosedNetworkError(err) { return nil } diff --git a/contract/pkg/mock/ddc_bucket_contract_mock.go b/contract/pkg/mock/ddc_bucket_contract_mock.go index e9f6f52..941d843 100644 --- a/contract/pkg/mock/ddc_bucket_contract_mock.go +++ b/contract/pkg/mock/ddc_bucket_contract_mock.go @@ -3,13 +3,14 @@ package mock import ( "encoding/json" "errors" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" "math" "math/big" "time" "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" log "github.com/sirupsen/logrus" ) @@ -228,7 +229,7 @@ func CreateBucket(bucketId uint32, clusterId uint32, bucketParams string, writer func getAccountIDs(ss58Addresses []string) []types.AccountID { accountIDs := make([]types.AccountID, len(ss58Addresses)) for i, address := range ss58Addresses { - if accountID, err := pkg.DecodeAccountIDFromSS58(address); err != nil { + if accountID, err := utils.DecodeAccountIDFromSS58(address); err != nil { log.Fatal("Failed decode private key ed25519") } else { accountIDs[i] = accountID @@ -238,6 +239,6 @@ func getAccountIDs(ss58Addresses []string) []types.AccountID { return accountIDs } -func (d *ddcBucketContractMock) GetEventDispatcher() map[types.Hash]pkg.ContractEventDispatchEntry { +func (d *ddcBucketContractMock) GetEventDispatcher() map[types.Hash]sdktypes.ContractEventDispatchEntry { return nil } diff --git a/contract/pkg/sdktypes/types.go b/contract/pkg/sdktypes/types.go new file mode 100644 index 0000000..e7fb563 --- /dev/null +++ b/contract/pkg/sdktypes/types.go @@ -0,0 +1,61 @@ +package sdktypes + +import ( + "context" + "github.com/centrifuge/go-substrate-rpc-client/v4/signature" + "github.com/centrifuge/go-substrate-rpc-client/v4/types" + "reflect" +) + +type ContractEventDispatchEntry struct { + ArgumentType reflect.Type + Handler ContractEventHandler +} + +type ContractEventHandler func(interface{}) + +type BlockchainClient interface { + CallToReadEncoded(contractAddressSS58 string, fromAddress string, method []byte, args ...interface{}) (string, error) + CallToExec(ctx context.Context, contractCall ContractCall) (types.Hash, error) + Deploy(ctx context.Context, deployCall DeployCall) (types.AccountID, error) + SetEventDispatcher(contractAddressSS58 string, dispatcher map[types.Hash]ContractEventDispatchEntry) error +} + +type Response struct { + DebugMessage string `json:"debugMessage"` + GasConsumed int `json:"gasConsumed"` + Result struct { + Ok struct { + Data string `json:"data"` + Flags int `json:"flags"` + } `json:"Ok"` + } `json:"result"` +} + +type Request struct { + Origin string `json:"origin"` + Dest string `json:"dest"` + GasLimit uint `json:"gasLimit"` + InputData string `json:"inputData"` + Value int `json:"value"` +} + +type DeployCall struct { + Code []byte + Salt []byte + From signature.KeyringPair + Value float64 + GasLimit float64 + Method []byte + Args []interface{} +} + +type ContractCall struct { + ContractAddress types.AccountID + ContractAddressSS58 string + From signature.KeyringPair + Value float64 + GasLimit float64 + Method []byte + Args []interface{} +} diff --git a/contract/pkg/utils.go b/contract/pkg/utils/utils.go similarity index 96% rename from contract/pkg/utils.go rename to contract/pkg/utils/utils.go index ff544a5..6dc6729 100644 --- a/contract/pkg/utils.go +++ b/contract/pkg/utils/utils.go @@ -1,4 +1,4 @@ -package pkg +package utils import ( "bytes" @@ -72,6 +72,6 @@ func GetContractData(method []byte, args ...interface{}) ([]byte, error) { return buf.Bytes(), nil } -func isClosedNetworkError(err error) bool { +func IsClosedNetworkError(err error) bool { return err != nil && strings.Contains(err.Error(), "use of closed network connection") } diff --git a/contract/pkg/utils_test.go b/contract/pkg/utils/utils_test.go similarity index 96% rename from contract/pkg/utils_test.go rename to contract/pkg/utils/utils_test.go index b46103f..fbbc35a 100644 --- a/contract/pkg/utils_test.go +++ b/contract/pkg/utils/utils_test.go @@ -1,4 +1,4 @@ -package pkg +package utils import ( "encoding/hex" diff --git a/test/setup_test.go b/test/setup_test.go index 8c32897..37ba707 100644 --- a/test/setup_test.go +++ b/test/setup_test.go @@ -5,8 +5,9 @@ import ( "encoding/hex" "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/bucket" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" "github.com/google/uuid" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -56,7 +57,7 @@ func TestApplicationSuite(t *testing.T) { suite.Run(t, new(ApplicationTestSuite)) } -func (a *ApplicationTestSuite) deployBucketContract(client pkg.BlockchainClient) (*types.AccountID, error) { +func (a *ApplicationTestSuite) deployBucketContract(client sdktypes.BlockchainClient) (*types.AccountID, error) { methodId, err := hex.DecodeString("9bae9d5e") // label: "new" if err != nil { logrus.WithError(err).Fatal("Can't decode method") @@ -66,7 +67,7 @@ func (a *ApplicationTestSuite) deployBucketContract(client pkg.BlockchainClient) return nil, err } - call := pkg.DeployCall{ + call := sdktypes.DeployCall{ Code: code, Salt: []byte(uuid.New().String()), From: signature.TestKeyringPairAlice, @@ -85,19 +86,19 @@ func (a *ApplicationTestSuite) deployBucketContract(client pkg.BlockchainClient) return &contract, nil } -func (a *ApplicationTestSuite) bucketSetAvailability(contractAddress string, client pkg.BlockchainClient, ctx context.Context, bucketId bucket.BucketId, avail bool) (string, error) { +func (a *ApplicationTestSuite) bucketSetAvailability(contractAddress string, client sdktypes.BlockchainClient, ctx context.Context, bucketId bucket.BucketId, avail bool) (string, error) { methodId, err := hex.DecodeString("053eb3ce") if err != nil { logrus.WithError(err).Fatal("Can't decode method") } - c, err := pkg.DecodeAccountIDFromSS58(contractAddress) + c, err := utils.DecodeAccountIDFromSS58(contractAddress) if err != nil { return "", err } arg1 := types.U32(bucketId) arg2 := types.NewBool(avail) - call := pkg.ContractCall{ + call := sdktypes.ContractCall{ ContractAddress: c, ContractAddressSS58: contractAddress, From: signature.TestKeyringPairAlice, @@ -117,12 +118,12 @@ func (a *ApplicationTestSuite) bucketSetAvailability(contractAddress string, cli return blockHash.Hex(), nil } -func (a *ApplicationTestSuite) bucketCreate(contractAddress string, client pkg.BlockchainClient, ctx context.Context) (string, error) { +func (a *ApplicationTestSuite) bucketCreate(contractAddress string, client sdktypes.BlockchainClient, ctx context.Context) (string, error) { methodId, err := hex.DecodeString("0aeb2379") if err != nil { logrus.WithError(err).Fatal("Can't decode method") } - c, err := pkg.DecodeAccountIDFromSS58(contractAddress) + c, err := utils.DecodeAccountIDFromSS58(contractAddress) if err != nil { return "", err } @@ -138,7 +139,7 @@ func (a *ApplicationTestSuite) bucketCreate(contractAddress string, client pkg.B alice := signature.TestKeyringPairAlice - call := pkg.ContractCall{ + call := sdktypes.ContractCall{ ContractAddress: c, ContractAddressSS58: contractAddress, From: alice, From 24f3bb7ca621d151793f09eec26f269f4248141c Mon Sep 17 00:00:00 2001 From: Max Levitskiy Date: Mon, 3 Jul 2023 14:48:45 +0200 Subject: [PATCH 3/3] [DDC | Storage Cluster | Delivery set 17] (Subscribe storage node to change topology blockchain event) Read events from the blockchain seens last block in case websocket was disconnected Add Cid field to Ack (#42) --- contract/go.mod | 1 + contract/go.sum | 1 + contract/pkg/bucket/messages_test.go | 4 +- contract/pkg/client.go | 169 ++++++++----- contract/pkg/client_test.go | 228 ++++++++++++++++++ .../mock/subscription_ChainSubscription.go | 75 ++++++ .../subscription_ChainSubscriptionFactory.go | 50 ++++ .../pkg/mock/subscription_EventDecoder.go | 50 ++++ contract/pkg/mock/subscription_Watchdog.go | 49 ++++ .../pkg/mock/subscription_WatchdogFactory.go | 50 ++++ contract/pkg/subscription/event_decorer.go | 27 +++ contract/pkg/subscription/subscription.go | 49 ++++ contract/pkg/subscription/watchdog.go | 37 +++ ddc-schemas | 2 +- go.work.sum | 4 +- 15 files changed, 735 insertions(+), 61 deletions(-) create mode 100644 contract/pkg/client_test.go create mode 100644 contract/pkg/mock/subscription_ChainSubscription.go create mode 100644 contract/pkg/mock/subscription_ChainSubscriptionFactory.go create mode 100644 contract/pkg/mock/subscription_EventDecoder.go create mode 100644 contract/pkg/mock/subscription_Watchdog.go create mode 100644 contract/pkg/mock/subscription_WatchdogFactory.go create mode 100644 contract/pkg/subscription/event_decorer.go create mode 100644 contract/pkg/subscription/subscription.go create mode 100644 contract/pkg/subscription/watchdog.go diff --git a/contract/go.mod b/contract/go.mod index 4be2a4b..e438000 100644 --- a/contract/go.mod +++ b/contract/go.mod @@ -4,6 +4,7 @@ require ( github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.8 github.com/decred/base58 v1.0.3 github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 + github.com/golang/mock v1.3.1 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 diff --git a/contract/go.sum b/contract/go.sum index 017d5a0..41f34a1 100644 --- a/contract/go.sum +++ b/contract/go.sum @@ -153,6 +153,7 @@ github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/contract/pkg/bucket/messages_test.go b/contract/pkg/bucket/messages_test.go index df9dcc1..2553236 100644 --- a/contract/pkg/bucket/messages_test.go +++ b/contract/pkg/bucket/messages_test.go @@ -2,7 +2,7 @@ package bucket import ( "encoding/hex" - "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" "strings" "testing" @@ -16,7 +16,7 @@ func TestBucketWriteAccess(t *testing.T) { publicKey := "0xd049e851567f16d68523a645ee96465ceb678ad983fc08e6a38408ad10410c4d" publicKeyB, _ := hex.DecodeString(strings.TrimPrefix(publicKey, "0x")) - accountID, _ := pkg.DecodeAccountIDFromSS58(ss58) + accountID, _ := utils.DecodeAccountIDFromSS58(ss58) bucketStatus := &BucketStatus{WriterIds: []types.AccountID{accountID}} //when diff --git a/contract/pkg/client.go b/contract/pkg/client.go index 45aaa82..184d98f 100644 --- a/contract/pkg/client.go +++ b/contract/pkg/client.go @@ -4,7 +4,9 @@ import ( "bytes" "context" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription" "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/utils" + "math" "os/signal" "reflect" "sync" @@ -23,13 +25,20 @@ const ( CERE = 10_000_000_000 ) +var ( + chainSubscriptionFactory = subscription.NewChainFactory() + watchdogFactory = subscription.NewWatchdogFactory() + watchdogTimeout = time.Minute +) + type ( blockchainClient struct { *gsrpc.SubstrateAPI eventContractAccount types.AccountID eventDispatcher map[types.Hash]sdktypes.ContractEventDispatchEntry - eventContextCancel context.CancelFunc + eventContextCancel []context.CancelFunc connectMutex sync.Mutex + eventDecoder subscription.EventDecoder } ) @@ -41,6 +50,7 @@ func CreateBlockchainClient(apiUrl string) sdktypes.BlockchainClient { return &blockchainClient{ SubstrateAPI: substrateAPI, + eventDecoder: subscription.NewEventDecoder(), } } @@ -69,25 +79,66 @@ func (b *blockchainClient) listenContractEvents() error { return err } - sub, err := b.RPC.State.SubscribeStorageRaw([]types.StorageKey{key}) + s, err := b.RPC.State.SubscribeStorageRaw([]types.StorageKey{key}) if err != nil { return err } + b.processChainSubscription(chainSubscriptionFactory.NewChainSubscription(s), key, meta) + return nil +} +func (b *blockchainClient) processChainSubscription(sub subscription.ChainSubscription, key types.StorageKey, meta *types.Metadata) { ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - b.eventContextCancel = cancel - watchdog := time.NewTicker(time.Minute) + b.eventContextCancel = append(b.eventContextCancel, cancel) + watchdog := watchdogFactory.NewWatchdog(watchdogTimeout) eventArrived := true - var lastEventBlock types.BlockNumber + var lastEventBlockHash types.Hash go func() { defer sub.Unsubscribe() for { select { case <-ctx.Done(): + log.Info("Chain subscription context done") return - case <-watchdog.C: + case <-watchdog.C(): if !eventArrived { + log.WithField("block", lastEventBlockHash.Hex()).Warn("Watchdog event timeout") + + // read missed blocks + lastEventBlock, err := b.RPC.Chain.GetBlock(lastEventBlockHash) + if err != nil { + log.WithError(err).Warn("Error fetching block") + break + } + lastEventBlockNumber := lastEventBlock.Block.Header.Number + headerLatest, err := b.RPC.Chain.GetHeaderLatest() + if err != nil { + log.WithError(err).Warn("Error fetching latest header") + } else if headerLatest.Number > lastEventBlockNumber { + for i := lastEventBlockNumber + 1; i <= headerLatest.Number; i++ { + missedBlock, err := b.RPC.Chain.GetBlockHash(uint64(i)) + if err != nil { + log.Println(err) + continue + } + storageData, err := b.RPC.State.GetStorageRaw(key, missedBlock) + if err != nil { + log.WithError(err).Error("Error fetching storage data") + continue + } + events, err := b.eventDecoder.DecodeEvents(*storageData, meta) + if err != nil { + log.WithError(err).Error("Error parsing events") + continue + } + + b.processEvents(events, missedBlock) + lastEventBlockHash = missedBlock + } + } + + // try to resubscribe s, err := b.RPC.State.SubscribeStorageRaw([]types.StorageKey{key}) if err != nil { log.WithError(err).Warn("Watchdog resubscribtion failed") @@ -95,7 +146,7 @@ func (b *blockchainClient) listenContractEvents() error { } log.Info("Watchdog event resubscribed") sub.Unsubscribe() - sub = s + sub = chainSubscriptionFactory.NewChainSubscription(s) } eventArrived = false @@ -108,13 +159,7 @@ func (b *blockchainClient) listenContractEvents() error { break } eventArrived = true - block, err := b.RPC.Chain.GetBlock(evt.Block) - if err != nil { - log.WithError(err).Warn("Error fetching block") - break - } - lastEventBlock = block.Block.Header.Number - print(lastEventBlock) + lastEventBlockHash = evt.Block // parse all events for this block for _, chng := range evt.Changes { @@ -123,54 +168,58 @@ func (b *blockchainClient) listenContractEvents() error { continue } - events := types.EventRecords{} - err = types.EventRecordsRaw(chng.StorageData).DecodeEventRecords(meta, &events) + storageData := chng.StorageData + events, err := b.eventDecoder.DecodeEvents(storageData, meta) if err != nil { - log.WithError(err).Warnf("Error parsing event %x", chng.StorageData[:]) + log.WithError(err).Warnf("Error parsing event %x", storageData[:]) continue } - for _, e := range events.Contracts_ContractEmitted { - if !b.eventContractAccount.Equal(&e.Contract) { - continue - } - - // Identify the event by matching one of its topics against known signatures. The topics are sorted so - // the needed one may be in the arbitrary position. - var dispatchEntry sdktypes.ContractEventDispatchEntry - found := false - for _, topic := range e.Topics { - dispatchEntry, found = b.eventDispatcher[topic] - if found { - break - } - } - if !found { - log.WithField("block", evt.Block.Hex()). - Warnf("Unknown event emitted by our contract: %x", e.Data[:16]) - continue - } - - if dispatchEntry.Handler == nil { - log.WithField("block", evt.Block.Hex()).WithField("event", dispatchEntry.ArgumentType.Name()). - Debug("Event unhandeled") - continue - } - args := reflect.New(dispatchEntry.ArgumentType).Interface() - if err := codec.Decode(e.Data[1:], args); err != nil { - log.WithError(err).WithField("block", evt.Block.Hex()). - WithField("event", dispatchEntry.ArgumentType.Name()). - Errorf("Cannot decode event data %x", e.Data) - } - log.WithField("block", evt.Block.Hex()).WithField("event", dispatchEntry.ArgumentType.Name()). - Debugf("Event args: %x", e.Data) - dispatchEntry.Handler(args) - } + b.processEvents(events, evt.Block) } } } }() - return nil +} + +func (b *blockchainClient) processEvents(events *types.EventRecords, blockHash types.Hash) { + for _, e := range events.Contracts_ContractEmitted { + if !b.eventContractAccount.Equal(&e.Contract) { + continue + } + + // Identify the event by matching one of its topics against known signatures. The topics are sorted so + // the needed one may be in the arbitrary position. + var dispatchEntry sdktypes.ContractEventDispatchEntry + found := false + for _, topic := range e.Topics { + dispatchEntry, found = b.eventDispatcher[topic] + if found { + break + } + } + if !found { + + log.WithField("block", blockHash.Hex()). + Warnf("Unknown event emitted by our contract: %x", e.Data[:uint32(math.Min(16, float64(len(e.Data))))]) + continue + } + + if dispatchEntry.Handler == nil { + log.WithField("block", blockHash.Hex()).WithField("event", dispatchEntry.ArgumentType.Name()). + Debug("Event unhandeled") + continue + } + args := reflect.New(dispatchEntry.ArgumentType).Interface() + if err := codec.Decode(e.Data[1:], args); err != nil { + log.WithError(err).WithField("block", blockHash.Hex()). + WithField("event", dispatchEntry.ArgumentType.Name()). + Errorf("Cannot decode event data %x", e.Data) + } + log.WithField("block", blockHash.Hex()).WithField("event", dispatchEntry.ArgumentType.Name()). + Debugf("Event args: %x", e.Data) + dispatchEntry.Handler(args) + } } func (b *blockchainClient) CallToReadEncoded(contractAddressSS58 string, fromAddress string, method []byte, args ...interface{}) (string, error) { @@ -410,9 +459,8 @@ func (b *blockchainClient) reconnect() error { return nil } - if b.eventContextCancel != nil { - b.eventContextCancel() - } + b.unsubscribeAll() + substrateAPI, err := gsrpc.NewSubstrateAPI(b.Client.URL()) if err != nil { log.WithError(err).Warningf("Blockchain client can't reconnect to %s", b.Client.URL()) @@ -428,3 +476,10 @@ func (b *blockchainClient) reconnect() error { return nil } + +func (b *blockchainClient) unsubscribeAll() { + for _, c := range b.eventContextCancel { + c() + } + b.eventContextCancel = nil +} diff --git a/contract/pkg/client_test.go b/contract/pkg/client_test.go new file mode 100644 index 0000000..3c5b51e --- /dev/null +++ b/contract/pkg/client_test.go @@ -0,0 +1,228 @@ +package pkg + +import ( + gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4" + "github.com/centrifuge/go-substrate-rpc-client/v4/rpc" + "github.com/centrifuge/go-substrate-rpc-client/v4/types" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/mock" + "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/sdktypes" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + "reflect" + "testing" + "time" +) + +func Test_blockchainClient_processChainSubscription(t *testing.T) { + // given + mockController := gomock.NewController(t) + chainSubscriptionMock := mock.NewMockChainSubscription(mockController) + chainSubscriptionMock.EXPECT().Err().Return(make(chan error)).AnyTimes() + storageChangeSetsChan := make(chan types.StorageChangeSet) + chainSubscriptionMock.EXPECT().Chan().Return(storageChangeSetsChan).AnyTimes() + chainSubscriptionMock.EXPECT().Unsubscribe().AnyTimes() + + chainSubscriptionFactoryMock := mock.NewMockChainSubscriptionFactory(mockController) + chainSubscriptionFactoryMock.EXPECT().NewChainSubscription(gomock.Any()).Return(chainSubscriptionMock).AnyTimes() + chainSubscriptionFactory = chainSubscriptionFactoryMock + + stateMock := mock.NewMockState(mockController) + stateMock.EXPECT().SubscribeStorageRaw(gomock.Any()).Return(nil, nil).AnyTimes() + chainMock := mock.NewMockChain(mockController) + //chainMock.EXPECT().GetBlock(gomock.Any()).Return(nil, nil).AnyTimes() + + watchdogMock := mock.NewMockWatchdog(mockController) + watchdogChan := make(chan time.Time) + watchdogMock.EXPECT().C().Return(watchdogChan).AnyTimes() + watchdogFactoryMock := mock.NewMockWatchdogFactory(mockController) + watchdogFactoryMock.EXPECT().NewWatchdog(gomock.Any()).Return(watchdogMock).AnyTimes() + watchdogFactory = watchdogFactoryMock + + eventDecoderMock := mock.NewMockEventDecoder(mockController) + + substrateAPI := &gsrpc.SubstrateAPI{ + RPC: &rpc.RPC{ + State: stateMock, + Chain: chainMock, + }, + } + + c := blockchainClient{ + SubstrateAPI: substrateAPI, + eventDecoder: eventDecoderMock, + } + c.eventDispatcher = make(map[types.Hash]sdktypes.ContractEventDispatchEntry) + + t.Run("should resubscribe when timeout", func(t *testing.T) { + h := types.NewHash([]byte{1}) + handlerChan := make(chan bool) + ticker := time.NewTicker(1 * time.Second) + go func() { + <-ticker.C + handlerChan <- false + }() + c.eventDispatcher[h] = sdktypes.ContractEventDispatchEntry{ + Handler: func(_ interface{}) { + handlerChan <- true + }, + ArgumentType: reflect.TypeOf(interface{}("")), + } + storageKey := h[:] + events := &types.EventRecords{ + Contracts_ContractEmitted: []types.EventContractsContractEmitted{ + { + Data: []byte("test"), + Topics: []types.Hash{ + h, + }, + }, + }, + } + eventDecoderMock.EXPECT().DecodeEvents(gomock.Any(), gomock.Any()).Return(events, nil).Times(1) + + c.processChainSubscription(chainSubscriptionMock, storageKey, createMetadata()) + watchdogChan <- time.Now() + storageChangeSetsChan <- types.StorageChangeSet{ + Changes: []types.KeyValueOption{ + { + HasStorageData: true, + StorageKey: storageKey, + }, + }, + } + assert.True(t, <-handlerChan) + c.unsubscribeAll() + }) + t.Run("should read missed events from the blockchain before resubscribing", func(t *testing.T) { + + h := types.NewHash([]byte{2}) + storageKey := h[:] + + metadata := createMetadata() + c.processChainSubscription(chainSubscriptionMock, storageKey, metadata) + + // trigger to save last block + events := &types.EventRecords{ + Contracts_ContractEmitted: []types.EventContractsContractEmitted{ + { + Data: []byte("test"), + Topics: []types.Hash{ + h, + }, + }, + }, + } + eventDecoderMock.EXPECT().DecodeEvents(gomock.Any(), gomock.Any()).Return(events, nil).Times(1) + lastBlockHash := types.NewHash([]byte{123}) + storageChangeSetsChan <- types.StorageChangeSet{ + Block: lastBlockHash, + Changes: []types.KeyValueOption{ + { + HasStorageData: true, + StorageKey: storageKey, + }, + }, + } + + // nothing after first watchdog tick + watchdogChan <- time.Now() + + // Set up mocks + // getting block number by hash + lastSignedBlock := &types.SignedBlock{ + Block: types.Block{ + Header: types.Header{ + Number: 1, + }, + }, + } + chainMock.EXPECT().GetBlock(lastBlockHash).Return(lastSignedBlock, nil).Times(1) + // getting current block number + currentSignedBlock := &types.Header{ + Number: 3, + } + chainMock.EXPECT().GetHeaderLatest().Return(currentSignedBlock, nil).Times(1) + + // return block hash by number + missedBlockHash2 := types.NewHash([]byte{22}) + missedBlockHash3 := types.NewHash([]byte{33}) + chainMock.EXPECT().GetBlockHash(uint64(2)).Return(missedBlockHash2, nil).Times(1) + chainMock.EXPECT().GetBlockHash(uint64(3)).Return(missedBlockHash3, nil).Times(1) + + // return storage data for missed blocks + storageDataRaw1 := types.StorageDataRaw{1} + storageDataRaw2 := types.StorageDataRaw{2} + stateMock.EXPECT().GetStorageRaw(storageKey, missedBlockHash2).Return(&storageDataRaw1, nil).Times(1) + stateMock.EXPECT().GetStorageRaw(storageKey, missedBlockHash3).Return(&storageDataRaw2, nil).Times(1) + + // return events for missed blocks + events2 := &types.EventRecords{ + Contracts_ContractEmitted: []types.EventContractsContractEmitted{ + { + Data: []byte("test2"), + Topics: []types.Hash{ + h, + }, + }, + }, + } + events3 := &types.EventRecords{ + Contracts_ContractEmitted: []types.EventContractsContractEmitted{ + { + Data: []byte("test3"), + Topics: []types.Hash{ + h, + }, + }, + }, + } + eventDecoderMock.EXPECT().DecodeEvents([]byte{1}, metadata).Return(events2, nil).Times(1) + eventDecoderMock.EXPECT().DecodeEvents([]byte{2}, metadata).Return(events3, nil).Times(1) + + // add subscriber to event + handlerChan := make(chan bool) + ticker := time.NewTicker(1 * time.Second) + go func() { + <-ticker.C + handlerChan <- false + }() + c.eventDispatcher[h] = sdktypes.ContractEventDispatchEntry{ + Handler: func(_ interface{}) { + handlerChan <- true + }, + ArgumentType: reflect.TypeOf(interface{}("")), + } + + // trigger second time, because we resubscribe if there is no event between two watchdog ticks + watchdogChan <- time.Now() + assert.True(t, <-handlerChan) + + c.unsubscribeAll() + }) + +} + +func createMetadata() *types.Metadata { + metadata := &types.Metadata{ + Version: 14, + AsMetadataV14: types.MetadataV14{ + Pallets: []types.PalletMetadataV14{ + { + HasStorage: true, + Storage: types.StorageMetadataV14{ + Prefix: "System", + Items: []types.StorageEntryMetadataV14{ + { + Name: "Events", + Type: types.StorageEntryTypeV14{ + IsPlainType: true, + }, + }, + }, + }, + }, + }, + }, + } + return metadata +} diff --git a/contract/pkg/mock/subscription_ChainSubscription.go b/contract/pkg/mock/subscription_ChainSubscription.go new file mode 100644 index 0000000..0605955 --- /dev/null +++ b/contract/pkg/mock/subscription_ChainSubscription.go @@ -0,0 +1,75 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription (interfaces: ChainSubscription) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + types "github.com/centrifuge/go-substrate-rpc-client/v4/types" + gomock "github.com/golang/mock/gomock" +) + +// MockChainSubscription is a mock of ChainSubscription interface. +type MockChainSubscription struct { + ctrl *gomock.Controller + recorder *MockChainSubscriptionMockRecorder +} + +// MockChainSubscriptionMockRecorder is the mock recorder for MockChainSubscription. +type MockChainSubscriptionMockRecorder struct { + mock *MockChainSubscription +} + +// NewMockChainSubscription creates a new mock instance. +func NewMockChainSubscription(ctrl *gomock.Controller) *MockChainSubscription { + mock := &MockChainSubscription{ctrl: ctrl} + mock.recorder = &MockChainSubscriptionMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChainSubscription) EXPECT() *MockChainSubscriptionMockRecorder { + return m.recorder +} + +// Chan mocks base method. +func (m *MockChainSubscription) Chan() <-chan types.StorageChangeSet { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Chan") + ret0, _ := ret[0].(<-chan types.StorageChangeSet) + return ret0 +} + +// Chan indicates an expected call of Chan. +func (mr *MockChainSubscriptionMockRecorder) Chan() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Chan", reflect.TypeOf((*MockChainSubscription)(nil).Chan)) +} + +// Err mocks base method. +func (m *MockChainSubscription) Err() <-chan error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Err") + ret0, _ := ret[0].(<-chan error) + return ret0 +} + +// Err indicates an expected call of Err. +func (mr *MockChainSubscriptionMockRecorder) Err() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Err", reflect.TypeOf((*MockChainSubscription)(nil).Err)) +} + +// Unsubscribe mocks base method. +func (m *MockChainSubscription) Unsubscribe() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Unsubscribe") +} + +// Unsubscribe indicates an expected call of Unsubscribe. +func (mr *MockChainSubscriptionMockRecorder) Unsubscribe() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unsubscribe", reflect.TypeOf((*MockChainSubscription)(nil).Unsubscribe)) +} diff --git a/contract/pkg/mock/subscription_ChainSubscriptionFactory.go b/contract/pkg/mock/subscription_ChainSubscriptionFactory.go new file mode 100644 index 0000000..79a3eae --- /dev/null +++ b/contract/pkg/mock/subscription_ChainSubscriptionFactory.go @@ -0,0 +1,50 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription (interfaces: ChainSubscriptionFactory) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + state "github.com/centrifuge/go-substrate-rpc-client/v4/rpc/state" + subscription "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription" + gomock "github.com/golang/mock/gomock" +) + +// MockChainSubscriptionFactory is a mock of ChainSubscriptionFactory interface. +type MockChainSubscriptionFactory struct { + ctrl *gomock.Controller + recorder *MockChainSubscriptionFactoryMockRecorder +} + +// MockChainSubscriptionFactoryMockRecorder is the mock recorder for MockChainSubscriptionFactory. +type MockChainSubscriptionFactoryMockRecorder struct { + mock *MockChainSubscriptionFactory +} + +// NewMockChainSubscriptionFactory creates a new mock instance. +func NewMockChainSubscriptionFactory(ctrl *gomock.Controller) *MockChainSubscriptionFactory { + mock := &MockChainSubscriptionFactory{ctrl: ctrl} + mock.recorder = &MockChainSubscriptionFactoryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChainSubscriptionFactory) EXPECT() *MockChainSubscriptionFactoryMockRecorder { + return m.recorder +} + +// NewChainSubscription mocks base method. +func (m *MockChainSubscriptionFactory) NewChainSubscription(arg0 *state.StorageSubscription) subscription.ChainSubscription { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewChainSubscription", arg0) + ret0, _ := ret[0].(subscription.ChainSubscription) + return ret0 +} + +// NewChainSubscription indicates an expected call of NewChainSubscription. +func (mr *MockChainSubscriptionFactoryMockRecorder) NewChainSubscription(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewChainSubscription", reflect.TypeOf((*MockChainSubscriptionFactory)(nil).NewChainSubscription), arg0) +} diff --git a/contract/pkg/mock/subscription_EventDecoder.go b/contract/pkg/mock/subscription_EventDecoder.go new file mode 100644 index 0000000..902622f --- /dev/null +++ b/contract/pkg/mock/subscription_EventDecoder.go @@ -0,0 +1,50 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription (interfaces: EventDecoder) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + types "github.com/centrifuge/go-substrate-rpc-client/v4/types" + gomock "github.com/golang/mock/gomock" +) + +// MockEventDecoder is a mock of EventDecoder interface. +type MockEventDecoder struct { + ctrl *gomock.Controller + recorder *MockEventDecoderMockRecorder +} + +// MockEventDecoderMockRecorder is the mock recorder for MockEventDecoder. +type MockEventDecoderMockRecorder struct { + mock *MockEventDecoder +} + +// NewMockEventDecoder creates a new mock instance. +func NewMockEventDecoder(ctrl *gomock.Controller) *MockEventDecoder { + mock := &MockEventDecoder{ctrl: ctrl} + mock.recorder = &MockEventDecoderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEventDecoder) EXPECT() *MockEventDecoderMockRecorder { + return m.recorder +} + +// DecodeEvents mocks base method. +func (m *MockEventDecoder) DecodeEvents(arg0 types.StorageDataRaw, arg1 *types.Metadata) (*types.EventRecords, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DecodeEvents", arg0, arg1) + ret0, _ := ret[0].(*types.EventRecords) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DecodeEvents indicates an expected call of DecodeEvents. +func (mr *MockEventDecoderMockRecorder) DecodeEvents(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecodeEvents", reflect.TypeOf((*MockEventDecoder)(nil).DecodeEvents), arg0, arg1) +} diff --git a/contract/pkg/mock/subscription_Watchdog.go b/contract/pkg/mock/subscription_Watchdog.go new file mode 100644 index 0000000..725dee5 --- /dev/null +++ b/contract/pkg/mock/subscription_Watchdog.go @@ -0,0 +1,49 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription (interfaces: Watchdog) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" +) + +// MockWatchdog is a mock of Watchdog interface. +type MockWatchdog struct { + ctrl *gomock.Controller + recorder *MockWatchdogMockRecorder +} + +// MockWatchdogMockRecorder is the mock recorder for MockWatchdog. +type MockWatchdogMockRecorder struct { + mock *MockWatchdog +} + +// NewMockWatchdog creates a new mock instance. +func NewMockWatchdog(ctrl *gomock.Controller) *MockWatchdog { + mock := &MockWatchdog{ctrl: ctrl} + mock.recorder = &MockWatchdogMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWatchdog) EXPECT() *MockWatchdogMockRecorder { + return m.recorder +} + +// C mocks base method. +func (m *MockWatchdog) C() <-chan time.Time { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "C") + ret0, _ := ret[0].(<-chan time.Time) + return ret0 +} + +// C indicates an expected call of C. +func (mr *MockWatchdogMockRecorder) C() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "C", reflect.TypeOf((*MockWatchdog)(nil).C)) +} diff --git a/contract/pkg/mock/subscription_WatchdogFactory.go b/contract/pkg/mock/subscription_WatchdogFactory.go new file mode 100644 index 0000000..9523b0d --- /dev/null +++ b/contract/pkg/mock/subscription_WatchdogFactory.go @@ -0,0 +1,50 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription (interfaces: WatchdogFactory) + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + time "time" + + subscription "github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription" + gomock "github.com/golang/mock/gomock" +) + +// MockWatchdogFactory is a mock of WatchdogFactory interface. +type MockWatchdogFactory struct { + ctrl *gomock.Controller + recorder *MockWatchdogFactoryMockRecorder +} + +// MockWatchdogFactoryMockRecorder is the mock recorder for MockWatchdogFactory. +type MockWatchdogFactoryMockRecorder struct { + mock *MockWatchdogFactory +} + +// NewMockWatchdogFactory creates a new mock instance. +func NewMockWatchdogFactory(ctrl *gomock.Controller) *MockWatchdogFactory { + mock := &MockWatchdogFactory{ctrl: ctrl} + mock.recorder = &MockWatchdogFactoryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWatchdogFactory) EXPECT() *MockWatchdogFactoryMockRecorder { + return m.recorder +} + +// NewWatchdog mocks base method. +func (m *MockWatchdogFactory) NewWatchdog(arg0 time.Duration) subscription.Watchdog { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewWatchdog", arg0) + ret0, _ := ret[0].(subscription.Watchdog) + return ret0 +} + +// NewWatchdog indicates an expected call of NewWatchdog. +func (mr *MockWatchdogFactoryMockRecorder) NewWatchdog(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewWatchdog", reflect.TypeOf((*MockWatchdogFactory)(nil).NewWatchdog), arg0) +} diff --git a/contract/pkg/subscription/event_decorer.go b/contract/pkg/subscription/event_decorer.go new file mode 100644 index 0000000..608b44e --- /dev/null +++ b/contract/pkg/subscription/event_decorer.go @@ -0,0 +1,27 @@ +package subscription + +import "github.com/centrifuge/go-substrate-rpc-client/v4/types" + +//go:generate mockgen -destination ../mock/subscription_EventDecoder.go -package mock github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription EventDecoder + +type EventDecoder interface { + DecodeEvents(data types.StorageDataRaw, m *types.Metadata) (*types.EventRecords, error) +} + +func NewEventDecoder() EventDecoder { + return &eventDecoder{} +} + +var _ EventDecoder = &eventDecoder{} + +type eventDecoder struct { +} + +func (e *eventDecoder) DecodeEvents(data types.StorageDataRaw, m *types.Metadata) (*types.EventRecords, error) { + events := types.EventRecords{} + err := types.EventRecordsRaw(data).DecodeEventRecords(m, &events) + if err != nil { + return nil, err + } + return &events, nil +} diff --git a/contract/pkg/subscription/subscription.go b/contract/pkg/subscription/subscription.go new file mode 100644 index 0000000..cc87e80 --- /dev/null +++ b/contract/pkg/subscription/subscription.go @@ -0,0 +1,49 @@ +package subscription + +import ( + "github.com/centrifuge/go-substrate-rpc-client/v4/rpc/state" + "github.com/centrifuge/go-substrate-rpc-client/v4/types" +) + +//go:generate mockgen -destination ../mock/subscription_ChainSubscription.go -package mock github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription ChainSubscription +//go:generate mockgen -destination ../mock/subscription_ChainSubscriptionFactory.go -package mock github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription ChainSubscriptionFactory + +type ChainSubscription interface { + Chan() <-chan types.StorageChangeSet + Err() <-chan error + Unsubscribe() +} + +type ChainSubscriptionFactory interface { + NewChainSubscription(sub *state.StorageSubscription) ChainSubscription +} + +var _ ChainSubscriptionFactory = &chainSubscriptionFactory{} + +type chainSubscriptionFactory struct { +} + +func NewChainFactory() ChainSubscriptionFactory { + return &chainSubscriptionFactory{} +} +func (p *chainSubscriptionFactory) NewChainSubscription(sub *state.StorageSubscription) ChainSubscription { + return &chainSubscription{sub} +} + +var _ ChainSubscription = &chainSubscription{} + +type chainSubscription struct { + sub *state.StorageSubscription +} + +func (c *chainSubscription) Chan() <-chan types.StorageChangeSet { + return c.sub.Chan() +} + +func (c *chainSubscription) Err() <-chan error { + return c.sub.Err() +} + +func (c *chainSubscription) Unsubscribe() { + c.sub.Unsubscribe() +} diff --git a/contract/pkg/subscription/watchdog.go b/contract/pkg/subscription/watchdog.go new file mode 100644 index 0000000..b7d176f --- /dev/null +++ b/contract/pkg/subscription/watchdog.go @@ -0,0 +1,37 @@ +package subscription + +import "time" + +//go:generate mockgen -destination=../mock/subscription_WatchdogFactory.go -package=mock github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription WatchdogFactory +//go:generate mockgen -destination=../mock/subscription_Watchdog.go -package=mock github.com/cerebellum-network/cere-ddc-sdk-go/contract/pkg/subscription Watchdog + +type Watchdog interface { + C() <-chan time.Time +} + +var _ Watchdog = &watchdog{} + +type watchdog struct { + *time.Ticker +} + +func (w *watchdog) C() <-chan time.Time { + return w.Ticker.C +} + +type WatchdogFactory interface { + NewWatchdog(timeout time.Duration) Watchdog +} + +type watchdogFactory struct { +} + +func (w *watchdogFactory) NewWatchdog(timeout time.Duration) Watchdog { + return &watchdog{ + Ticker: time.NewTicker(timeout), + } +} + +func NewWatchdogFactory() WatchdogFactory { + return &watchdogFactory{} +} diff --git a/ddc-schemas b/ddc-schemas index 3e4f5c7..b4d9841 160000 --- a/ddc-schemas +++ b/ddc-schemas @@ -1 +1 @@ -Subproject commit 3e4f5c709554972de98f2e3b9051090630d10c3f +Subproject commit b4d98417f1c10b0c4f9a141e34026401a045d266 diff --git a/go.work.sum b/go.work.sum index 204f7ae..55509d9 100644 --- a/go.work.sum +++ b/go.work.sum @@ -135,7 +135,6 @@ github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg= @@ -217,11 +216,14 @@ go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk= go.opentelemetry.io/otel/exporters/jaeger v1.4.1/go.mod h1:ZW7vkOu9nC1CxsD8bHNHCia5JUbwP39vxgd1q4Z5rCI= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=