From a4d5c00b9a94f3bf8881ca88c1a475fd33e59531 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Thu, 2 Sep 2021 07:45:50 -0300 Subject: [PATCH] feat(testutil): add `testutil` pkg to generate sample objects (#10) * add testutil pkg to generate sample objects * add unit test --- testutil/sample/sample.go | 13 +++++++++++++ testutil/sample/sample_test.go | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 testutil/sample/sample.go create mode 100644 testutil/sample/sample_test.go diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go new file mode 100644 index 0000000..98f2153 --- /dev/null +++ b/testutil/sample/sample.go @@ -0,0 +1,13 @@ +package sample + +import ( + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// AccAddress returns a sample account address +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +} diff --git a/testutil/sample/sample_test.go b/testutil/sample/sample_test.go new file mode 100644 index 0000000..8558544 --- /dev/null +++ b/testutil/sample/sample_test.go @@ -0,0 +1,15 @@ +package sample + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestAccAddress(t *testing.T) { + got := AccAddress() + require.NotEmpty(t, got) + _, err := sdk.AccAddressFromBech32(got) + require.NoError(t, err) +}