diff --git a/Makefile b/Makefile index 6d991923..b83464a9 100644 --- a/Makefile +++ b/Makefile @@ -403,6 +403,7 @@ mock: ## Generate all the mocks (for tests) @echo "${COLOR_CYAN} 🧱 Generating all the mocks${COLOR_RESET}" @go install github.com/golang/mock/mockgen@v1.6.0 @mockgen -source=x/logic/types/expected_keepers.go -package testutil -destination x/logic/testutil/expected_keepers_mocks.go + @mockgen -source=x/logic/fs/fs.go -package testutil -destination x/logic/testutil/fs_mocks.go ## Release: .PHONY: release-assets diff --git a/app/app.go b/app/app.go index a7741906..2f40332c 100644 --- a/app/app.go +++ b/app/app.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/fs" "net/http" "os" "path/filepath" @@ -1017,7 +1016,7 @@ func (app *App) SimulationManager() *module.SimulationManager { // provideFS is used to provide the virtual file system used for the logic module // to load external file. -func (app *App) provideFS(ctx context.Context) fs.FS { +func (app *App) provideFS(ctx context.Context) logicfs.FS { wasmHandler := logicfs.NewWasmHandler(app.WasmKeeper) return logicfs.NewVirtualFS(ctx, []logicfs.URIHandler{wasmHandler}) } diff --git a/x/logic/fs/fs.go b/x/logic/fs/fs.go index 9529e6ab..b7c50004 100644 --- a/x/logic/fs/fs.go +++ b/x/logic/fs/fs.go @@ -5,6 +5,10 @@ import ( "io/fs" ) +type FS interface { + fs.FS +} + // VirtualFS is the custom virtual file system used into the blockchain. // It will hold a list of handler that can resolve file URI and return the corresponding binary file. type VirtualFS struct { @@ -12,7 +16,7 @@ type VirtualFS struct { router Router } -var _ fs.FS = (*VirtualFS)(nil) +var _ FS = (*VirtualFS)(nil) // NewVirtualFS return a new VirtualFS object that will handle all virtual file on the interpreter. // File can be provided from different sources like CosmWasm cw-storage smart contract. diff --git a/x/logic/keeper/keeper.go b/x/logic/keeper/keeper.go index 2d638a46..3999ff4e 100644 --- a/x/logic/keeper/keeper.go +++ b/x/logic/keeper/keeper.go @@ -3,12 +3,12 @@ package keeper import ( goctx "context" "fmt" - "io/fs" "github.com/cosmos/cosmos-sdk/codec" 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/okp4/okp4d/x/logic/fs" "github.com/okp4/okp4d/x/logic/types" "github.com/tendermint/tendermint/libs/log" ) diff --git a/x/logic/testutil/fs_mocks.go b/x/logic/testutil/fs_mocks.go new file mode 100644 index 00000000..89c9f8ef --- /dev/null +++ b/x/logic/testutil/fs_mocks.go @@ -0,0 +1,50 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/logic/fs/fs.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + fs "io/fs" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" +) + +// MockFS is a mock of FS interface. +type MockFS struct { + ctrl *gomock.Controller + recorder *MockFSMockRecorder +} + +// MockFSMockRecorder is the mock recorder for MockFS. +type MockFSMockRecorder struct { + mock *MockFS +} + +// NewMockFS creates a new mock instance. +func NewMockFS(ctrl *gomock.Controller) *MockFS { + mock := &MockFS{ctrl: ctrl} + mock.recorder = &MockFSMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFS) EXPECT() *MockFSMockRecorder { + return m.recorder +} + +// Open mocks base method. +func (m *MockFS) Open(name string) (fs.File, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Open", name) + ret0, _ := ret[0].(fs.File) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Open indicates an expected call of Open. +func (mr *MockFSMockRecorder) Open(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockFS)(nil).Open), name) +} diff --git a/x/logic/testutil/logic.go b/x/logic/testutil/logic.go index 6613fbff..84179f21 100644 --- a/x/logic/testutil/logic.go +++ b/x/logic/testutil/logic.go @@ -7,6 +7,7 @@ import ( "github.com/ichiban/prolog" "github.com/ichiban/prolog/engine" + "github.com/okp4/okp4d/x/logic/fs" ) // NewInterpreterMust returns a new Interpreter with the given context or panics if it fails. @@ -16,6 +17,7 @@ func NewInterpreterMust(ctx context.Context) (interpreter *prolog.Interpreter) { interpreter.Register3(engine.NewAtom("op"), engine.Op) interpreter.Register3(engine.NewAtom("compare"), engine.Compare) interpreter.Register2(engine.NewAtom("="), engine.Unify) + interpreter.Register1(engine.NewAtom("consult"), engine.Consult) err := interpreter.Compile(ctx, ` :-(op(1200, xfx, ':-')). @@ -34,6 +36,13 @@ func NewInterpreterMust(ctx context.Context) (interpreter *prolog.Interpreter) { return } +func NewInterpreterWithFSMust(ctx context.Context, filesystem fs.FS) (interpreter *prolog.Interpreter) { + interpreter = NewInterpreterMust(ctx) + interpreter.FS = filesystem + + return +} + // CompileMust compiles the given source code and panics if it fails. // This is a convenience function for testing. func CompileMust(ctx context.Context, interpreter *prolog.Interpreter, s string, args ...interface{}) {