-
Notifications
You must be signed in to change notification settings - Fork 7
/
auth_engine.go
36 lines (29 loc) · 1.21 KB
/
auth_engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package testutil
import (
"testing"
"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/sourcenetwork/sourcehub/x/acp/auth_engine"
"github.com/sourcenetwork/sourcehub/x/acp/auth_engine/zanzi"
"github.com/sourcenetwork/sourcehub/x/acp/types"
)
// GetTestAuthEngine returns an Auth Engine bound to a test
// using the Zanzi Engine implementation
func GetTestAuthEngine(t *testing.T) (auth_engine.AuthEngine, storetypes.CommitMultiStore, sdk.Context) {
storeKey := storetypes.NewKVStoreKey(types.StoreKey)
db := dbm.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
require.NoError(t, stateStore.LoadLatestVersion())
kv := stateStore.GetCommitKVStore(storeKey)
engine, err := zanzi.NewZanzi(kv, log.NewNopLogger())
require.Nil(t, err)
ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())
return engine, stateStore, ctx
}