Skip to content

fix(tm2/gnovm): improve error for coins handling #4930

@MikaelVallenet

Description

@MikaelVallenet

Description

in tm2/pkg/std in func (coins Coins) Add(coinsB Coins) Coins.

func (coins Coins) Add(coinsB Coins) Coins {
	res := coins.AddUnsafe(coinsB)
	if !res.IsValid() {
		panic(fmt.Sprintf("invalid result: %v + %v = %v", coins, coinsB, res))
	}
	return res
}

The function IsValid asserts the Coins are sorted, have positive amount, and Denom does not contain upper case characters.

The problem is for example if i have a coin set that have upper case the error is not explicit at all.

example this:

	coinsToSend := chain.NewCoins(
		chain.NewCoin("coinA", 500),
		chain.NewCoin("coinB", 300),
	)

	alice := testutils.TestAddress("alice")
	testing.SetOriginCaller(alice)
	testing.SetRealm(testing.NewUserRealm(alice))
	testing.IssueCoins(alice, coinsToSend)

testing.IssueCoin will use the function stated above

The error i got is: panic: invalid result: + 500coinA = 500coinA-> no explicit or implicit hint to guess it's because i put an uppercase letter.

Where i would expect: panic: invalid coinA denom, a valid denom should not contain uppercase.

We can either check it before or explicitly stated in the error all the possible reason our coins are not valid.
Maybe check others places where there is Coins operations.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions