Skip to content

Commit

Permalink
Merge pull request #885 from tendermint/audit-release
Browse files Browse the repository at this point in the history
Release v0.2.1
  • Loading branch information
lumtis authored Jul 6, 2022
2 parents f5d9d70 + a217c11 commit 09f44be
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 85 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
github.com/tendermint/starport v0.19.5
github.com/tendermint/tendermint v0.34.16
github.com/tendermint/tm-db v0.6.6
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.27.1
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -59,6 +59,7 @@ require (
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -116,7 +117,7 @@ require (
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
)

Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,9 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
Expand Down Expand Up @@ -2078,7 +2079,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
Expand Down Expand Up @@ -2211,8 +2211,9 @@ google.golang.org/genproto v0.0.0-20211203200212-54befc351ae9/go.mod h1:5CzLGKJ6
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e h1:fNKDNuUyC4WH+inqDMpfXDdfvwfYILbsX+oskGZ8hxg=
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand All @@ -2229,8 +2230,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down Expand Up @@ -2276,8 +2278,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
Expand Down
6 changes: 3 additions & 3 deletions x/campaign/keeper/mainnet_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (k Keeper) SetMainnetAccount(ctx sdk.Context, mainnetAccount types.MainnetAccount) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))
b := k.cdc.MustMarshal(&mainnetAccount)
store.Set(types.MainnetAccountKey(
store.Set(types.AccountKeyPath(
mainnetAccount.CampaignID,
mainnetAccount.Address,
), b)
Expand All @@ -25,7 +25,7 @@ func (k Keeper) GetMainnetAccount(
) (val types.MainnetAccount, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))

b := store.Get(types.MainnetAccountKey(campaignID, address))
b := store.Get(types.AccountKeyPath(campaignID, address))
if b == nil {
return val, false
}
Expand All @@ -41,7 +41,7 @@ func (k Keeper) RemoveMainnetAccount(
address string,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetAccountKeyPrefix))
store.Delete(types.MainnetAccountKey(
store.Delete(types.AccountKeyPath(
campaignID,
address,
))
Expand Down
6 changes: 3 additions & 3 deletions x/campaign/keeper/mainnet_vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (k Keeper) SetMainnetVestingAccount(ctx sdk.Context, mainnetVestingAccount types.MainnetVestingAccount) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetVestingAccountKeyPrefix))
b := k.cdc.MustMarshal(&mainnetVestingAccount)
store.Set(types.MainnetVestingAccountKey(
store.Set(types.AccountKeyPath(
mainnetVestingAccount.CampaignID,
mainnetVestingAccount.Address,
), b)
Expand All @@ -25,7 +25,7 @@ func (k Keeper) GetMainnetVestingAccount(
) (val types.MainnetVestingAccount, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetVestingAccountKeyPrefix))

b := store.Get(types.MainnetVestingAccountKey(campaignID, address))
b := store.Get(types.AccountKeyPath(campaignID, address))
if b == nil {
return val, false
}
Expand All @@ -41,7 +41,7 @@ func (k Keeper) RemoveMainnetVestingAccount(
address string,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MainnetVestingAccountKeyPrefix))
store.Delete(types.MainnetVestingAccountKey(campaignID, address))
store.Delete(types.AccountKeyPath(campaignID, address))
}

// GetAllMainnetVestingAccount returns all mainnetVestingAccount
Expand Down
6 changes: 5 additions & 1 deletion x/campaign/keeper/msg_add_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func (k msgServer) AddShares(goCtx context.Context, msg *types.MsgAddShares) (*t

// increase the campaign shares
campaign.AllocatedShares = types.IncreaseShares(campaign.AllocatedShares, msg.Shares)
if types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx)) {
reached, err := types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx))
if err != nil {
return nil, spnerrors.Criticalf("verified shares are invalid %s", err.Error())
}
if reached {
return nil, sdkerrors.Wrapf(types.ErrTotalSharesLimit, "%d", msg.CampaignID)
}

Expand Down
6 changes: 5 additions & 1 deletion x/campaign/keeper/msg_add_vesting_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func (k msgServer) AddVestingOptions(goCtx context.Context, msg *types.MsgAddVes

// increase the campaign shares
campaign.AllocatedShares = types.IncreaseShares(campaign.AllocatedShares, totalShares)
if types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx)) {
reached, err := types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx))
if err != nil {
return nil, spnerrors.Criticalf("verified shares are invalid %s", err.Error())
}
if reached {
return nil, sdkerrors.Wrapf(types.ErrTotalSharesLimit, "%d", msg.CampaignID)
}

Expand Down
6 changes: 5 additions & 1 deletion x/campaign/keeper/msg_mint_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (k msgServer) MintVouchers(goCtx context.Context, msg *types.MsgMintVoucher

// Increase the campaign shares
campaign.AllocatedShares = types.IncreaseShares(campaign.AllocatedShares, msg.Shares)
if types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx)) {
reached, err := types.IsTotalSharesReached(campaign.AllocatedShares, k.GetTotalShares(ctx))
if err != nil {
return nil, spnerrors.Criticalf("verified shares are invalid %s", err.Error())
}
if reached {
return nil, sdkerrors.Wrapf(types.ErrTotalSharesLimit, "%d", msg.CampaignID)
}

Expand Down
12 changes: 6 additions & 6 deletions x/campaign/types/campaign.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package types

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -33,12 +33,12 @@ func (m Campaign) Validate(totalShareNumber uint64) error {
if !m.TotalSupply.IsValid() {
return errors.New("invalid total supply")
}
if !sdk.Coins(m.AllocatedShares).IsValid() {
return errors.New("invalid allocated shares")
}

if IsTotalSharesReached(m.AllocatedShares, totalShareNumber) {

reached, err := IsTotalSharesReached(m.AllocatedShares, totalShareNumber)
if err != nil {
return errors.Wrap(err, "invalid allocated shares")
}
if reached {
return errors.New("more allocated shares than total shares")
}

Expand Down
4 changes: 3 additions & 1 deletion x/campaign/types/campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func TestCampaign_Validate(t *testing.T) {
totalSharesReached.AllocatedShares = campaign.NewSharesFromCoins(sdk.NewCoins(
sdk.NewCoin("foo", sdk.NewInt(spntypes.TotalShareNumber+1)),
))
require.True(t, campaign.IsTotalSharesReached(totalSharesReached.AllocatedShares, spntypes.TotalShareNumber))
reached, err := campaign.IsTotalSharesReached(totalSharesReached.AllocatedShares, spntypes.TotalShareNumber)
require.NoError(t, err)
require.True(t, reached)

for _, tc := range []struct {
desc string
Expand Down
4 changes: 2 additions & 2 deletions x/campaign/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (gs GenesisState) Validate() error {
return fmt.Errorf("campaign id %d doesn't exist for mainnet account %s",
elem.CampaignID, elem.Address)
}
index := string(MainnetAccountKey(elem.CampaignID, elem.Address))
index := string(AccountKeyPath(elem.CampaignID, elem.Address))
if _, ok := mainnetAccountIndexMap[index]; ok {
return fmt.Errorf("duplicated index for mainnetAccount")
}
Expand All @@ -73,7 +73,7 @@ func (gs GenesisState) Validate() error {
return fmt.Errorf("campaign id %d doesn't exist for mainnet vesting account %s",
elem.CampaignID, elem.Address)
}
index := string(MainnetVestingAccountKey(elem.CampaignID, elem.Address))
index := string(AccountKeyPath(elem.CampaignID, elem.Address))
if _, ok := mainnetVestingAccountIndexMap[index]; ok {
return fmt.Errorf("duplicated index for mainnetVestingAccount")
}
Expand Down
11 changes: 2 additions & 9 deletions x/campaign/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func CampaignChainsKey(campaignID uint64) []byte {
return append(spntypes.UintBytes(campaignID), byte('/'))
}

// MainnetAccountKey returns the store key to retrieve a MainnetAccount from the index fields
func MainnetAccountKey(campaignID uint64, address string) []byte {
// AccountKeyPath returns the store key path without prefix for an account defined by a campaign ID and an address
func AccountKeyPath(campaignID uint64, address string) []byte {
campaignIDBytes := append(spntypes.UintBytes(campaignID), byte('/'))
addressBytes := append([]byte(address), byte('/'))
return append(campaignIDBytes, addressBytes...)
Expand All @@ -60,13 +60,6 @@ func MainnetAccountAllKey(campaignID uint64) []byte {
return append(prefixBytes, campaignIDBytes...)
}

// MainnetVestingAccountKey returns the store key to retrieve a MainnetVestingAccount from the index fields
func MainnetVestingAccountKey(campaignID uint64, address string) []byte {
campaignIDBytes := append(spntypes.UintBytes(campaignID), byte('/'))
addressBytes := append([]byte(address), byte('/'))
return append(campaignIDBytes, addressBytes...)
}

// MainnetVestingAccountAllKey returns the store key to retrieve all MainnetVestingAccount by campaign id
func MainnetVestingAccountAllKey(campaignID uint64) []byte {
prefixBytes := []byte(MainnetVestingAccountKeyPrefix)
Expand Down
15 changes: 11 additions & 4 deletions x/campaign/types/shares.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package types

import (
"errors"
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
)

// Shares represents the portion of a supply
Expand Down Expand Up @@ -73,14 +73,21 @@ func DecreaseShares(shares, toDecrease Shares) (Shares, error) {
}

// IsTotalSharesReached checks if the provided shares overflow the total number of shares
func IsTotalSharesReached(shares Shares, maximumTotalShareNumber uint64) bool {
func IsTotalSharesReached(shares Shares, maximumTotalShareNumber uint64) (bool, error) {
if err := sdk.Coins(shares).Validate(); err != nil {
return false, errors.Wrap(err, "invalid share")
}
if err := CheckShares(shares); err != nil {
return false, errors.Wrap(err, "invalid share format")
}

for _, coin := range shares {
if coin.Amount.Uint64() > maximumTotalShareNumber {
return true
return true, nil
}
}

return false
return false, nil
}

// IsAllLTE returns true iff for every denom in shares, the denom is present at
Expand Down
59 changes: 46 additions & 13 deletions x/campaign/types/shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,61 @@ func TestDecreaseShares(t *testing.T) {

func TestShareIsTotalReached(t *testing.T) {
for _, tc := range []struct {
desc string
shares campaign.Shares
reached bool
desc string
shares campaign.Shares
maxTotalShares uint64
reached bool
isValid bool
}{
{
desc: "empty is false",
shares: campaign.EmptyShares(),
reached: false,
desc: "should return false with empty shares",
shares: campaign.EmptyShares(),
maxTotalShares: 0,
reached: false,
isValid: true,
},
{
desc: "no default total is reached",
shares: tc.Shares(t, fmt.Sprintf("%dfoo,100bar", spntypes.TotalShareNumber)),
reached: false,
desc: "should return false when total not reached",
shares: tc.Shares(t, "1000foo,100bar"),
maxTotalShares: 1000,
reached: false,
isValid: true,
},
{
desc: "a default total is reached",
shares: tc.Shares(t, fmt.Sprintf("%dfoo,100bar", spntypes.TotalShareNumber+1)),
reached: true,
desc: "should return true when total reached",
shares: tc.Shares(t, "1001foo,100bar"),
maxTotalShares: 1000,
reached: true,
isValid: true,
},
{
desc: "should return error if shares are invalid",
shares: campaign.NewSharesFromCoins(sdk.Coins{
sdk.NewCoin("foo", sdk.NewIntFromUint64(500)),
sdk.NewCoin("foo", sdk.NewIntFromUint64(500)),
}),
maxTotalShares: 1000,
reached: false,
isValid: false,
},
{
desc: "should return error if shares have invalid format",
shares: campaign.Shares(sdk.Coins{
sdk.NewCoin("foo", sdk.NewIntFromUint64(500)),
}),
maxTotalShares: 1000,
reached: false,
isValid: false,
},
} {
t.Run(tc.desc, func(t *testing.T) {
require.Equal(t, tc.reached, campaign.IsTotalSharesReached(tc.shares, spntypes.TotalShareNumber))
reached, err := campaign.IsTotalSharesReached(tc.shares, tc.maxTotalShares)
if tc.isValid {
require.NoError(t, err)
require.True(t, tc.reached == reached)
} else {
require.Error(t, err)
}
})
}
}
Expand Down
Loading

0 comments on commit 09f44be

Please sign in to comment.