forked from classic-terra/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Blv/whitelist wallet v1 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StrathCole
merged 4 commits into
StrathCole:whitelisting-v1
from
BLV-Labs:blv/whitelist_wallet_v1
May 13, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| syntax = "proto3"; | ||
| package terra.taxexemption.v1; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "terra/taxexemption/v1/taxexemption.proto"; | ||
|
|
||
| option go_package = "github.com/classic-terra/core/v3/x/taxexemption/types"; | ||
|
|
||
| // GenesisState defines the taxexemption module's genesis state. | ||
| message GenesisState { | ||
|
|
||
| repeated Zone zone_list = 1 [ | ||
| (gogoproto.moretags) = "yaml:\"zone_list\"", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| repeated AddressesByZone addresses_by_zone = 2 [ | ||
| (gogoproto.moretags) = "yaml:\"addresses_by_zone\"", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
| } | ||
|
|
||
| message AddressesByZone { | ||
| string zone = 1 [(gogoproto.moretags) = "yaml:\"zone\""]; | ||
| repeated string addresses = 2 [(gogoproto.moretags) = "yaml:\"addresses\""]; | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,29 +1,118 @@ | ||
| package taxexemption | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
| "sort" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/store/prefix" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| "github.com/classic-terra/core/v3/x/taxexemption/keeper" | ||
| "github.com/classic-terra/core/v3/x/taxexemption/types" | ||
| ) | ||
|
|
||
| // NewGenesisState creates a new GenesisState object | ||
| func NewGenesisState() *types.GenesisState { | ||
| return &types.GenesisState{} | ||
| } | ||
|
|
||
| // DefaultGenesisState gets raw genesis raw message for testing | ||
| func DefaultGenesisState() *types.GenesisState { | ||
| return &types.GenesisState{} | ||
| return &types.GenesisState{ | ||
| ZoneList: []types.Zone{}, | ||
| AddressesByZone: []types.AddressesByZone{}, | ||
| } | ||
| } | ||
|
|
||
| // ValidateGenesis validates the provided oracle genesis state to ensure the | ||
| // expected invariants holds. (i.e. params in correct bounds, no duplicate validators) | ||
| func ValidateGenesis(data *types.GenesisState) error { | ||
| if len(data.ZoneList) != len(data.AddressesByZone) { | ||
| return types.ErrZoneLengthInvalid | ||
| } | ||
|
|
||
| zones := []string{} | ||
| for _, zone := range data.ZoneList { | ||
| zones = append(zones, zone.Name) | ||
| } | ||
|
|
||
| for _, addressesByZone := range data.AddressesByZone { | ||
| if !slices.Contains(zones, addressesByZone.Zone) { | ||
| return types.ErrZoneNotExist | ||
| } | ||
|
|
||
| for _, address := range addressesByZone.Addresses { | ||
| if _, err := sdk.AccAddressFromBech32(address); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // InitGenesis initializes default parameters | ||
| // and the keeper's address to pubkey map | ||
| func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) {} | ||
| func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) { | ||
| // Set the zone list | ||
| for _, zone := range data.ZoneList { | ||
| keeper.AddTaxExemptionZone(ctx, zone) | ||
| } | ||
|
|
||
| // Set the addresses by zone | ||
| for _, addressesByZone := range data.AddressesByZone { | ||
| for _, address := range addressesByZone.Addresses { | ||
| keeper.AddTaxExemptionAddress(ctx, addressesByZone.Zone, address) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ExportGenesis writes the current store values | ||
| // to a genesis file, which can be imported again | ||
| // with InitGenesis | ||
| func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisState) { | ||
| return types.NewGenesisState() | ||
| zonePrefix := prefix.NewStore(ctx.KVStore(keeper.StoreKey()), types.TaxExemptionZonePrefix) | ||
| iterator := zonePrefix.Iterator(nil, nil) | ||
| defer iterator.Close() | ||
|
|
||
| var zones []types.Zone | ||
| zoneAddresses := make(map[string][]string) | ||
| var addresesByZone []types.AddressesByZone | ||
|
|
||
| for ; iterator.Valid(); iterator.Next() { | ||
| var zone types.Zone | ||
| keeper.Codec().MustUnmarshal(iterator.Value(), &zone) | ||
| zones = append(zones, zone) | ||
| zoneAddresses[zone.Name] = []string{} | ||
| } | ||
|
|
||
| addressesPrefix := prefix.NewStore(ctx.KVStore(keeper.StoreKey()), types.TaxExemptionListPrefix) | ||
| iterator = addressesPrefix.Iterator(nil, nil) | ||
| defer iterator.Close() | ||
|
|
||
| for ; iterator.Valid(); iterator.Next() { | ||
| zoneName := string(iterator.Value()) | ||
| if _, ok := zoneAddresses[zoneName]; ok { | ||
| zoneAddresses[zoneName] = append(zoneAddresses[zoneName], string(iterator.Key())) | ||
| } | ||
| } | ||
|
|
||
| var zoneNames []string | ||
| for zoneName := range zoneAddresses { | ||
| zoneNames = append(zoneNames, zoneName) | ||
| } | ||
| sort.Strings(zoneNames) | ||
|
|
||
| for _, zoneName := range zoneNames { | ||
| addresses := zoneAddresses[zoneName] | ||
| addresesByZone = append(addresesByZone, types.AddressesByZone{ | ||
| Zone: zoneName, | ||
| Addresses: addresses, | ||
| }) | ||
| } | ||
|
|
||
| state := &types.GenesisState{ | ||
| ZoneList: zones, | ||
| AddressesByZone: addresesByZone, | ||
| } | ||
| err := ValidateGenesis(state) | ||
| if err != nil { | ||
| panic(fmt.Sprint("error validate genesis: ", err)) | ||
| } | ||
| return state | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,38 +1,156 @@ | ||
| package taxexemption_test | ||
|
|
||
| import ( | ||
| "slices" | ||
| "testing" | ||
|
|
||
| taxexemption "github.com/classic-terra/core/v3/x/taxexemption" | ||
| ultil "github.com/classic-terra/core/v3/x/taxexemption/keeper" | ||
| util "github.com/classic-terra/core/v3/x/taxexemption/keeper" | ||
| "github.com/classic-terra/core/v3/x/taxexemption/types" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestNewGenesisState(t *testing.T) { | ||
| genesis := types.NewGenesisState() | ||
| require.NotNil(t, genesis) | ||
| } | ||
|
|
||
| func TestDefaultGenesisState(t *testing.T) { | ||
| genesis := taxexemption.DefaultGenesisState() | ||
| require.NotNil(t, genesis) | ||
| } | ||
|
|
||
| func TestInitAndExportGenesis_Empty(t *testing.T) { | ||
| // Setup mock context & keeper (simple zero value for now) | ||
| input := ultil.CreateTestInput(t) | ||
| input := util.CreateTestInput(t) | ||
| k := input.TaxExemptionKeeper | ||
| ctx := sdk.Context{} | ||
|
|
||
| // Initialize genesis with empty state | ||
| genesis := taxexemption.NewGenesisState() | ||
| genesis := taxexemption.DefaultGenesisState() | ||
| require.NotNil(t, genesis) | ||
|
|
||
| taxexemption.InitGenesis(ctx, k, genesis) | ||
| taxexemption.InitGenesis(input.Ctx, k, genesis) | ||
|
|
||
| // Export genesis and check that it's not nil and matches default state | ||
| exported := taxexemption.ExportGenesis(ctx, k) | ||
| exported := taxexemption.ExportGenesis(input.Ctx, k) | ||
| require.NotNil(t, exported) | ||
| } | ||
|
|
||
| func TestInitAndExportGenesis_NonEmpty(t *testing.T) { | ||
| // Setup mock context & keeper (simple zero value for now) | ||
| input := util.CreateTestInput(t) | ||
| k := input.TaxExemptionKeeper | ||
|
|
||
| addresses := []string{ | ||
| util.Addrs[0].String(), | ||
| util.Addrs[1].String(), | ||
| } | ||
| slices.Sort(addresses) | ||
| // Initialize genesis with empty state | ||
| genesis := taxexemption.DefaultGenesisState() | ||
| genesis.ZoneList = []types.Zone{ | ||
| { | ||
| Name: "test-zone", | ||
| Incoming: true, | ||
| Outgoing: true, | ||
| CrossZone: true, | ||
| }, | ||
| } | ||
| genesis.AddressesByZone = []types.AddressesByZone{ | ||
| { | ||
| Zone: "test-zone", | ||
| Addresses: addresses, | ||
| }, | ||
| } | ||
| require.NotNil(t, genesis) | ||
|
|
||
| taxexemption.InitGenesis(input.Ctx, k, genesis) | ||
|
|
||
| // Export genesis and check that it's not nil and matches default state | ||
| exportedGenesis := taxexemption.ExportGenesis(input.Ctx, k) | ||
| require.NotNil(t, exportedGenesis) | ||
|
|
||
| require.Equal(t, genesis, exportedGenesis) | ||
| } | ||
|
|
||
| func TestValidateGenesis_Success(t *testing.T) { | ||
| // Initialize genesis with empty state | ||
| genesis := taxexemption.DefaultGenesisState() | ||
| genesis.ZoneList = []types.Zone{ | ||
| { | ||
| Name: "test-zone", | ||
| Incoming: true, | ||
| Outgoing: true, | ||
| CrossZone: true, | ||
| }, | ||
| } | ||
| genesis.AddressesByZone = []types.AddressesByZone{ | ||
| { | ||
| Zone: "test-zone", | ||
| Addresses: []string{ | ||
| util.Addrs[0].String(), | ||
| util.Addrs[1].String(), | ||
| }, | ||
| }, | ||
| } | ||
| require.NotNil(t, genesis) | ||
|
|
||
| err := taxexemption.ValidateGenesis(genesis) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestValidateGenesis_Failure(t *testing.T) { | ||
| // Case 1: Zone length mismatch | ||
| genesis := taxexemption.DefaultGenesisState() | ||
| genesis.ZoneList = []types.Zone{ | ||
| { | ||
| Name: "test-zone", | ||
| Incoming: true, | ||
| Outgoing: true, | ||
| CrossZone: true, | ||
| }, | ||
| } | ||
| genesis.AddressesByZone = []types.AddressesByZone{} | ||
|
|
||
| err := taxexemption.ValidateGenesis(genesis) | ||
| require.ErrorContains(t, err, "length of zone list and addresses by zone must be equal") | ||
|
|
||
| // Case 2: Invalid address | ||
| genesis = taxexemption.DefaultGenesisState() | ||
| genesis.ZoneList = []types.Zone{ | ||
| { | ||
| Name: "test-zone", | ||
| Incoming: true, | ||
| Outgoing: true, | ||
| CrossZone: true, | ||
| }, | ||
| } | ||
| genesis.AddressesByZone = []types.AddressesByZone{ | ||
| { | ||
| Zone: "test-zone", | ||
| Addresses: []string{ | ||
| "invalid-address", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err = taxexemption.ValidateGenesis(genesis) | ||
| require.ErrorContains(t, err, "decoding bech32 failed") | ||
|
|
||
| // Case 3: Zone not exist | ||
| genesis = taxexemption.DefaultGenesisState() | ||
| genesis.ZoneList = []types.Zone{ | ||
| { | ||
| Name: "test-zone", | ||
| Incoming: true, | ||
| Outgoing: true, | ||
| CrossZone: true, | ||
| }, | ||
| } | ||
| genesis.AddressesByZone = []types.AddressesByZone{ | ||
| { | ||
| Zone: "non-existent-zone", | ||
| Addresses: []string{ | ||
| util.Addrs[0].String(), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err = taxexemption.ValidateGenesis(genesis) | ||
| require.ErrorContains(t, err, "zone not exist") | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.