-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(collections): IndexedMap (#14397)
Co-authored-by: testinginprod <[email protected]> Co-authored-by: Marko <[email protected]> Co-authored-by: Likhita Polavarapu <[email protected]>
- Loading branch information
1 parent
ed17f2d
commit 519630e
Showing
21 changed files
with
891 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package colltest | ||
|
||
import "testing" | ||
|
||
type animal interface { | ||
name() string | ||
} | ||
|
||
type dog struct { | ||
Name string `json:"name"` | ||
BarksLoudly bool `json:"barks_loudly"` | ||
} | ||
|
||
type cat struct { | ||
Name string `json:"name"` | ||
Scratches bool `json:"scratches"` | ||
} | ||
|
||
func (d *cat) name() string { return d.Name } | ||
|
||
func (d dog) name() string { return d.Name } | ||
|
||
func TestMockValueCodec(t *testing.T) { | ||
t.Run("primitive type", func(t *testing.T) { | ||
x := MockValueCodec[string]() | ||
TestValueCodec(t, x, "hello") | ||
}) | ||
|
||
t.Run("struct type", func(t *testing.T) { | ||
x := MockValueCodec[dog]() | ||
TestValueCodec(t, x, dog{ | ||
Name: "kernel", | ||
BarksLoudly: true, | ||
}) | ||
}) | ||
|
||
t.Run("interface type", func(t *testing.T) { | ||
x := MockValueCodec[animal]() | ||
TestValueCodec[animal](t, x, dog{ | ||
Name: "kernel", | ||
BarksLoudly: true, | ||
}) | ||
TestValueCodec[animal](t, x, &cat{ | ||
Name: "echo", | ||
Scratches: true, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package colltest | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/core/store" | ||
db "github.com/cosmos/cosmos-db" | ||
) | ||
|
||
// MockStore returns a mock store.KVStoreService and a mock context.Context. | ||
// They can be used to test collections. | ||
func MockStore() (store.KVStoreService, context.Context) { | ||
kv := db.NewMemDB() | ||
return &testStore{kv}, context.Background() | ||
} | ||
|
||
type testStore struct { | ||
db db.DB | ||
} | ||
|
||
func (t testStore) OpenKVStore(ctx context.Context) store.KVStore { | ||
return t | ||
} | ||
|
||
func (t testStore) Get(key []byte) ([]byte, error) { | ||
return t.db.Get(key) | ||
} | ||
|
||
func (t testStore) Has(key []byte) (bool, error) { | ||
return t.db.Has(key) | ||
} | ||
|
||
func (t testStore) Set(key, value []byte) error { | ||
return t.db.Set(key, value) | ||
} | ||
|
||
func (t testStore) Delete(key []byte) error { | ||
return t.db.Delete(key) | ||
} | ||
|
||
func (t testStore) Iterator(start, end []byte) (store.Iterator, error) { | ||
return t.db.Iterator(start, end) | ||
} | ||
|
||
func (t testStore) ReverseIterator(start, end []byte) (store.Iterator, error) { | ||
return t.db.ReverseIterator(start, end) | ||
} | ||
|
||
var _ store.KVStore = testStore{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.