-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gov params for permissioned eco credits (#425)
Closes: #425 Add new gov params for permissioned credit creation Fix error in app/regen/cmd/genaccounts.go - couldn't compile due to error of cdc casting to itself
- Loading branch information
1 parent
3265a86
commit 7b7d2f8
Showing
11 changed files
with
433 additions
and
52 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
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,134 @@ | ||
package ecocredit | ||
|
||
import ( | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestDefaultParams(t *testing.T) { | ||
expected := Params{ | ||
CreditClassFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultCreditClassFeeTokens)), | ||
AllowedClassDesigners: []string{}, | ||
AllowlistEnabled: false, | ||
} | ||
df := DefaultParams() | ||
|
||
require.Equal(t, df.String(), expected.String()) | ||
} | ||
|
||
func Test_validateAllowlistCreditCreators(t *testing.T) { | ||
|
||
genAddrs := make([]string, 0, 3) | ||
for i := 0; i < 3; i++ { | ||
genAddrs = append(genAddrs, sdk.MustBech32ifyAddressBytes(sdk.Bech32MainPrefix, []byte(fmt.Sprintf("testaddr-%d", i)))) | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
args interface{} | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid creator list", | ||
args: genAddrs, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid creator list", | ||
args: []string{"bogus", "superbogus", "megabogus"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "mix of invalid/valid", | ||
args: []string{"bogus", genAddrs[0]}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "wrong type", | ||
args: []int{1, 2, 3, 4, 5}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "not even an array", | ||
args: "bruh", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateAllowlistCreditDesigners(tt.args); (err != nil) != tt.wantErr { | ||
t.Errorf("validateAllowlistCreditCreators() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_validateAllowlistEnabled(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
args interface{} | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid boolean value", | ||
args: true, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "valid boolean v2", | ||
args: false, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid type", | ||
args: []string{"lol", "rofl"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "seems valid but its not", | ||
args: 0, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateAllowlistEnabled(tt.args); (err != nil) != tt.wantErr { | ||
t.Errorf("validateAllowlistEnabled() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_validateCreditClassFee(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args interface{} | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid credit fee", | ||
args: sdk.NewCoins(sdk.NewCoin("regen", sdk.NewInt(45)), sdk.NewCoin("osmo", sdk.NewInt(32))), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "no fee is valid", | ||
args: sdk.NewCoins(), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid type", | ||
args: 45, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateCreditClassFee(tt.args); (err != nil) != tt.wantErr { | ||
t.Errorf("validateCreditClassFee() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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.