From 4b06d683b24b6cd64bf43a09f5c7c21672023e39 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 13 Feb 2024 21:14:53 +0530 Subject: [PATCH 01/10] add env bundler to accounts module --- simapp/app.go | 6 +----- x/accounts/keeper.go | 20 ++++++++------------ x/accounts/utils_test.go | 9 +++++++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 8533a40f725b..64dd0ac851f2 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -287,11 +287,7 @@ func NewSimApp( // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[accounts.StoreKey]), - runtime.EventService{}, - runtime.HeaderService{}, - runtime.BranchService{}, - runtime.GasService{}, + runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey])), addressCodec, appCodec, app.MsgServiceRouter(), diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 89ef637f808c..055ff7959e59 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -13,10 +13,9 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/branch" "cosmossdk.io/core/event" - "cosmossdk.io/core/gas" - "cosmossdk.io/core/header" "cosmossdk.io/core/store" "cosmossdk.io/x/accounts/accountstd" "cosmossdk.io/x/accounts/internal/implementation" @@ -71,11 +70,7 @@ type InterfaceRegistry interface { func NewKeeper( cdc codec.BinaryCodec, - ss store.KVStoreService, - es event.Service, - hs header.Service, - bs branch.Service, - gs gas.Service, + env appmodule.Environment, addressCodec address.Codec, signerProvider SignerProvider, execRouter MsgRouter, @@ -83,12 +78,13 @@ func NewKeeper( ir InterfaceRegistry, accounts ...accountstd.AccountCreatorFunc, ) (Keeper, error) { - sb := collections.NewSchemaBuilder(ss) + storeService := env.KVStoreService + sb := collections.NewSchemaBuilder(storeService) keeper := Keeper{ - storeService: ss, - eventService: es, + storeService: storeService, + eventService: env.EventService, addressCodec: addressCodec, - branchExecutor: bs, + branchExecutor: env.BranchService, msgRouter: execRouter, signerProvider: signerProvider, queryRouter: queryRouter, @@ -105,7 +101,7 @@ func NewKeeper( return Keeper{}, err } keeper.Schema = schema - keeper.accounts, err = implementation.MakeAccountsMap(cdc, keeper.addressCodec, hs, gs, accounts) + keeper.accounts, err = implementation.MakeAccountsMap(cdc, keeper.addressCodec, env.HeaderService, env.GasService, accounts) if err != nil { return Keeper{}, err } diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 94b53d96bbaa..b941210648c2 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -12,7 +12,10 @@ import ( "cosmossdk.io/collections/colltest" "cosmossdk.io/core/address" "cosmossdk.io/core/event" + storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/accounts/internal/implementation" + + "github.com/cosmos/cosmos-sdk/runtime" ) var _ address.Codec = (*addressCodec)(nil) @@ -46,8 +49,10 @@ func (i interfaceRegistry) RegisterImplementations(any, ...gogoproto.Message) {} func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Keeper, context.Context) { t.Helper() - ss, ctx := colltest.MockStore() - m, err := NewKeeper(nil, ss, eventService{}, nil, nil, nil, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) + _, ctx := colltest.MockStore() + key := storetypes.NewKVStoreKey(StoreKey) + env := runtime.NewEnvironment(runtime.NewKVStoreService(key)) + m, err := NewKeeper(nil, env, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx } From 75d4dbc4d1db2b95a73f12bfb3b48109a87353c8 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 13 Feb 2024 21:33:54 +0530 Subject: [PATCH 02/10] fix few tests --- x/accounts/go.mod | 7 ++++++- x/accounts/go.sum | 24 ++++++++++++++++++++++++ x/accounts/utils_test.go | 6 ++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/x/accounts/go.mod b/x/accounts/go.mod index 0d60f709dfca..d65a93b3faa0 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -7,6 +7,7 @@ require ( cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 cosmossdk.io/depinject v1.0.0-alpha.4 + cosmossdk.io/store v1.0.2 github.com/cosmos/cosmos-sdk v0.51.0 github.com/cosmos/gogoproto v1.4.11 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -21,8 +22,9 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.2.0 // indirect - cosmossdk.io/store v1.0.2 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect + cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000 // indirect + cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -76,6 +78,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/handlers v1.5.2 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -97,11 +100,13 @@ require ( github.com/klauspost/compress v1.17.6 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect + github.com/lib/pq v1.10.7 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/linxGnu/grocksdb v1.8.12 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/minio/highwayhash v1.0.2 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect diff --git a/x/accounts/go.sum b/x/accounts/go.sum index 1f20daa76e00..19c2daf11f61 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -17,6 +17,8 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMb github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0= github.com/99designs/keyring v1.2.2/go.mod h1:wes/FrByc8j7lFOAGLGSNEg8f/PaI3cgTBqhFkHUrPk= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= @@ -27,12 +29,16 @@ github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwS github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I= +github.com/adlio/schema v1.3.3/go.mod h1:1EsRssiv9/Ce2CMzq5DoL7RiMshhuigQxrR4DMV9fHg= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -67,6 +73,7 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtyd github.com/bufbuild/protocompile v0.5.1 h1:mixz5lJX4Hiz4FpqFREJHIXLfaLBntfaJv1h+/jS+Qg= github.com/bufbuild/protocompile v0.5.1/go.mod h1:G5iLmavmF4NsYtpZFvE3B/zFch2GIY8+wjsYLR/lc40= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= @@ -109,6 +116,8 @@ github.com/cometbft/cometbft v0.38.5 h1:4lOcK5VTPrfbLOhNHmPYe6c7eDXHtBdMCQuKbAfF github.com/cometbft/cometbft v0.38.5/go.mod h1:0tqKin+KQs8zDwzYD8rPHzSBIDNPuB4NrwwGDNb/hUg= github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo= github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0= +github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= +github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -160,6 +169,10 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= @@ -512,6 +525,12 @@ github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9 github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034= +github.com/opencontainers/image-spec v1.1.0-rc2/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w= +github.com/opencontainers/runc v1.1.3/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -520,6 +539,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= +github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -610,6 +631,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -789,6 +812,7 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index b941210648c2..b6c931420d77 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -12,7 +12,6 @@ import ( "cosmossdk.io/collections/colltest" "cosmossdk.io/core/address" "cosmossdk.io/core/event" - storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/accounts/internal/implementation" "github.com/cosmos/cosmos-sdk/runtime" @@ -49,9 +48,8 @@ func (i interfaceRegistry) RegisterImplementations(any, ...gogoproto.Message) {} func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Keeper, context.Context) { t.Helper() - _, ctx := colltest.MockStore() - key := storetypes.NewKVStoreKey(StoreKey) - env := runtime.NewEnvironment(runtime.NewKVStoreService(key)) + ss, ctx := colltest.MockStore() + env := runtime.NewEnvironment(ss) m, err := NewKeeper(nil, env, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx From 589298d71370662355553b8508e97dd4241e47b3 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 13 Feb 2024 22:36:44 +0530 Subject: [PATCH 03/10] fix tests --- simapp/app.go | 1 + x/accounts/keeper.go | 3 ++- x/accounts/utils_test.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 64dd0ac851f2..f85917b3fdf3 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -288,6 +288,7 @@ func NewSimApp( accountsKeeper, err := accounts.NewKeeper( appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey])), + runtime.EventService{}, addressCodec, appCodec, app.MsgServiceRouter(), diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 055ff7959e59..11c19c63537a 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -71,6 +71,7 @@ type InterfaceRegistry interface { func NewKeeper( cdc codec.BinaryCodec, env appmodule.Environment, + es event.Service, addressCodec address.Codec, signerProvider SignerProvider, execRouter MsgRouter, @@ -82,7 +83,7 @@ func NewKeeper( sb := collections.NewSchemaBuilder(storeService) keeper := Keeper{ storeService: storeService, - eventService: env.EventService, + eventService: es, addressCodec: addressCodec, branchExecutor: env.BranchService, msgRouter: execRouter, diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index b6c931420d77..4c8093677acc 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -50,7 +50,7 @@ func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Kee t.Helper() ss, ctx := colltest.MockStore() env := runtime.NewEnvironment(ss) - m, err := NewKeeper(nil, env, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) + m, err := NewKeeper(nil, env, eventService{}, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx } From 5f5b307e856351345ed7da2ed7d7ae7465777e07 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Feb 2024 10:37:13 +0530 Subject: [PATCH 04/10] add env to keeper --- x/accounts/keeper.go | 12 ++++-------- x/accounts/keeper_account_abstraction.go | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 11c19c63537a..2e4c2ef4872d 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -14,9 +14,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/branch" "cosmossdk.io/core/event" - "cosmossdk.io/core/store" "cosmossdk.io/x/accounts/accountstd" "cosmossdk.io/x/accounts/internal/implementation" @@ -82,10 +80,9 @@ func NewKeeper( storeService := env.KVStoreService sb := collections.NewSchemaBuilder(storeService) keeper := Keeper{ - storeService: storeService, + environment: env, eventService: es, addressCodec: addressCodec, - branchExecutor: env.BranchService, msgRouter: execRouter, signerProvider: signerProvider, queryRouter: queryRouter, @@ -112,10 +109,9 @@ func NewKeeper( type Keeper struct { // deps coming from the runtime - storeService store.KVStoreService + environment appmodule.Environment eventService event.Service addressCodec address.Codec - branchExecutor branch.Service msgRouter MsgRouter signerProvider SignerProvider queryRouter QueryRouter @@ -277,7 +273,7 @@ func (k Keeper) makeAccountContext(ctx context.Context, accountNumber uint64, ac if !isQuery { return implementation.MakeAccountContext( ctx, - k.storeService, + k.environment.KVStoreService, accountNumber, accountAddr, sender, @@ -292,7 +288,7 @@ func (k Keeper) makeAccountContext(ctx context.Context, accountNumber uint64, ac // and does not allow to get the sender. return implementation.MakeAccountContext( ctx, - k.storeService, + k.environment.KVStoreService, accountNumber, accountAddr, nil, diff --git a/x/accounts/keeper_account_abstraction.go b/x/accounts/keeper_account_abstraction.go index 3820baa3e984..d89b1a330ca6 100644 --- a/x/accounts/keeper_account_abstraction.go +++ b/x/accounts/keeper_account_abstraction.go @@ -77,7 +77,7 @@ func (k Keeper) Authenticate( op *v1.UserOperation, ) (gasUsed uint64, err error) { // authenticate - gasUsed, err = k.branchExecutor.ExecuteWithGasLimit(ctx, op.AuthenticationGasLimit, func(ctx context.Context) error { + gasUsed, err = k.environment.BranchService.ExecuteWithGasLimit(ctx, op.AuthenticationGasLimit, func(ctx context.Context) error { return k.authenticate(ctx, bundler, op) }) if err != nil { @@ -117,7 +117,7 @@ func (k Keeper) OpExecuteMessages( op *v1.UserOperation, ) (gasUsed uint64, responses []*implementation.Any, err error) { // execute messages, the real operation intent - gasUsed, err = k.branchExecutor.ExecuteWithGasLimit(ctx, op.ExecutionGasLimit, func(ctx context.Context) error { + gasUsed, err = k.environment.BranchService.ExecuteWithGasLimit(ctx, op.ExecutionGasLimit, func(ctx context.Context) error { responses, err = k.opExecuteMessages(ctx, bundler, op) return err }) @@ -170,7 +170,7 @@ func (k Keeper) PayBundler( op *v1.UserOperation, ) (gasUsed uint64, responses []*implementation.Any, err error) { // pay bundler - gasUsed, err = k.branchExecutor.ExecuteWithGasLimit(ctx, op.BundlerPaymentGasLimit, func(ctx context.Context) error { + gasUsed, err = k.environment.BranchService.ExecuteWithGasLimit(ctx, op.BundlerPaymentGasLimit, func(ctx context.Context) error { responses, err = k.payBundler(ctx, bundler, op) return err }) From 079ccfa01a8e943f44252a636b14ecbb13e783eb Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Feb 2024 10:49:03 +0530 Subject: [PATCH 05/10] run go mod tidy --- x/accounts/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/accounts/go.mod b/x/accounts/go.mod index d65a93b3faa0..669c87fd9395 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -7,7 +7,6 @@ require ( cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 cosmossdk.io/depinject v1.0.0-alpha.4 - cosmossdk.io/store v1.0.2 github.com/cosmos/cosmos-sdk v0.51.0 github.com/cosmos/gogoproto v1.4.11 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -22,6 +21,7 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.2.0 // indirect + cosmossdk.io/store v1.0.2 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect From 8ca3c223904c9a7d363ca370e18474a897f39c4f Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Feb 2024 10:54:51 +0530 Subject: [PATCH 06/10] wip --- x/accounts/keeper.go | 3 +++ x/accounts/utils_test.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 2e4c2ef4872d..ebd1deaf0996 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/event" + "cosmossdk.io/log" "cosmossdk.io/x/accounts/accountstd" "cosmossdk.io/x/accounts/internal/implementation" @@ -82,6 +83,7 @@ func NewKeeper( keeper := Keeper{ environment: env, eventService: es, + logger: env.Logger, addressCodec: addressCodec, msgRouter: execRouter, signerProvider: signerProvider, @@ -116,6 +118,7 @@ type Keeper struct { signerProvider SignerProvider queryRouter QueryRouter makeSendCoinsMsg coinsTransferMsgFunc + logger log.Logger accounts map[string]implementation.Implementation diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 4c8093677acc..09301eab2374 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/collections/colltest" "cosmossdk.io/core/address" "cosmossdk.io/core/event" + "cosmossdk.io/log" "cosmossdk.io/x/accounts/internal/implementation" "github.com/cosmos/cosmos-sdk/runtime" @@ -49,7 +50,7 @@ func (i interfaceRegistry) RegisterImplementations(any, ...gogoproto.Message) {} func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Keeper, context.Context) { t.Helper() ss, ctx := colltest.MockStore() - env := runtime.NewEnvironment(ss) + env := runtime.NewEnvironment(ss, log.NewNopLogger()) m, err := NewKeeper(nil, env, eventService{}, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx From d09892f525d42c827af4cc366eda7cff73bdea0b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Feb 2024 10:58:23 +0530 Subject: [PATCH 07/10] fix simapp --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index 3ff832bf34d9..894ae101ac4e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -287,7 +287,7 @@ func NewSimApp( // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey])), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger), runtime.EventService{}, addressCodec, appCodec, From 4a305121901978704aaeb2f61606c55fa0d615fd Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Feb 2024 22:18:56 +0530 Subject: [PATCH 08/10] fix nit --- x/accounts/go.mod | 2 +- x/accounts/keeper.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x/accounts/go.mod b/x/accounts/go.mod index 669c87fd9395..9a654f6ff460 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -7,6 +7,7 @@ require ( cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 cosmossdk.io/depinject v1.0.0-alpha.4 + cosmossdk.io/log v1.3.1 github.com/cosmos/cosmos-sdk v0.51.0 github.com/cosmos/gogoproto v1.4.11 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -19,7 +20,6 @@ require ( require ( cosmossdk.io/errors v1.0.1 // indirect - cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.2.0 // indirect cosmossdk.io/store v1.0.2 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index ebd1deaf0996..fdf00c4ff6e6 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -78,8 +78,7 @@ func NewKeeper( ir InterfaceRegistry, accounts ...accountstd.AccountCreatorFunc, ) (Keeper, error) { - storeService := env.KVStoreService - sb := collections.NewSchemaBuilder(storeService) + sb := collections.NewSchemaBuilder(env.KVStoreService) keeper := Keeper{ environment: env, eventService: es, From 745566330256f34b29dfa4a3832d24996569c3e5 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 15 Feb 2024 19:15:00 +0530 Subject: [PATCH 09/10] remove eventService --- simapp/app.go | 1 - x/accounts/keeper.go | 4 ---- x/accounts/msg_server.go | 2 +- x/accounts/utils_test.go | 17 +---------------- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index e2d7c8139d26..cda676f0f129 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -289,7 +289,6 @@ func NewSimApp( accountsKeeper, err := accounts.NewKeeper( appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger), - runtime.EventService{}, addressCodec, appCodec, app.MsgServiceRouter(), diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 89aeca045fa1..58afcd2b47df 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -14,7 +14,6 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/event" "cosmossdk.io/log" "cosmossdk.io/x/accounts/accountstd" "cosmossdk.io/x/accounts/internal/implementation" @@ -65,7 +64,6 @@ type InterfaceRegistry interface { func NewKeeper( cdc codec.BinaryCodec, env appmodule.Environment, - es event.Service, addressCodec address.Codec, signerProvider SignerProvider, execRouter MsgRouter, @@ -76,7 +74,6 @@ func NewKeeper( sb := collections.NewSchemaBuilder(env.KVStoreService) keeper := Keeper{ environment: env, - eventService: es, logger: env.Logger, addressCodec: addressCodec, msgRouter: execRouter, @@ -106,7 +103,6 @@ func NewKeeper( type Keeper struct { // deps coming from the runtime environment appmodule.Environment - eventService event.Service addressCodec address.Codec msgRouter MsgRouter signerProvider SignerProvider diff --git a/x/accounts/msg_server.go b/x/accounts/msg_server.go index 03abc2d85371..62c0776e1982 100644 --- a/x/accounts/msg_server.go +++ b/x/accounts/msg_server.go @@ -42,7 +42,7 @@ func (m msgServer) Init(ctx context.Context, request *v1.MsgInit) (*v1.MsgInitRe return nil, err } - eventManager := m.k.eventService.EventManager(ctx) + eventManager := m.k.environment.EventService.EventManager(ctx) err = eventManager.EmitKV( "account_creation", event.NewAttribute("address", accAddrString), diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 09301eab2374..1d9de2458280 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -11,7 +11,6 @@ import ( "cosmossdk.io/collections/colltest" "cosmossdk.io/core/address" - "cosmossdk.io/core/event" "cosmossdk.io/log" "cosmossdk.io/x/accounts/internal/implementation" @@ -25,20 +24,6 @@ type addressCodec struct{} func (a addressCodec) StringToBytes(text string) ([]byte, error) { return []byte(text), nil } func (a addressCodec) BytesToString(bz []byte) (string, error) { return string(bz), nil } -type eventService struct{} - -func (e eventService) Emit(event protoiface.MessageV1) error { return nil } - -func (e eventService) EmitKV(eventType string, attrs ...event.Attribute) error { - return nil -} - -func (e eventService) EmitNonConsensus(event protoiface.MessageV1) error { - return nil -} - -func (e eventService) EventManager(ctx context.Context) event.Manager { return e } - var _ InterfaceRegistry = (*interfaceRegistry)(nil) type interfaceRegistry struct{} @@ -51,7 +36,7 @@ func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Kee t.Helper() ss, ctx := colltest.MockStore() env := runtime.NewEnvironment(ss, log.NewNopLogger()) - m, err := NewKeeper(nil, env, eventService{}, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) + m, err := NewKeeper(nil, env, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx } From 502be01121895f79f27813379cf7230f6a22d26d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 15 Feb 2024 19:48:38 +0530 Subject: [PATCH 10/10] fix test --- x/accounts/utils_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 1d9de2458280..dc7ac535052c 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/collections/colltest" "cosmossdk.io/core/address" + "cosmossdk.io/core/event" "cosmossdk.io/log" "cosmossdk.io/x/accounts/internal/implementation" @@ -24,6 +25,20 @@ type addressCodec struct{} func (a addressCodec) StringToBytes(text string) ([]byte, error) { return []byte(text), nil } func (a addressCodec) BytesToString(bz []byte) (string, error) { return string(bz), nil } +type eventService struct{} + +func (e eventService) Emit(event protoiface.MessageV1) error { return nil } + +func (e eventService) EmitKV(eventType string, attrs ...event.Attribute) error { + return nil +} + +func (e eventService) EmitNonConsensus(event protoiface.MessageV1) error { + return nil +} + +func (e eventService) EventManager(ctx context.Context) event.Manager { return e } + var _ InterfaceRegistry = (*interfaceRegistry)(nil) type interfaceRegistry struct{} @@ -36,6 +51,7 @@ func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Kee t.Helper() ss, ctx := colltest.MockStore() env := runtime.NewEnvironment(ss, log.NewNopLogger()) + env.EventService = eventService{} m, err := NewKeeper(nil, env, addressCodec{}, nil, nil, nil, interfaceRegistry{}, accounts...) require.NoError(t, err) return m, ctx