Skip to content
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

support for tokens restricted with attributes #1377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
ffbbc10
add new marker property for required attributes
nullpointer0x00 Feb 16, 2023
922bad6
add back proofs.proto
nullpointer0x00 Feb 16, 2023
478e438
add proto property, temp fix on proto gen
nullpointer0x00 Feb 16, 2023
031d96f
inject attribute keeper into marker, fix tests
nullpointer0x00 Feb 16, 2023
2752639
add required attributes to txs
nullpointer0x00 Feb 16, 2023
e1a34a8
add name value required list
nullpointer0x00 Feb 16, 2023
47e8a9b
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Feb 16, 2023
d2e3ae7
revert changes to required attributes
nullpointer0x00 Feb 17, 2023
3cb59ae
missed revert
nullpointer0x00 Feb 17, 2023
8b921e5
add required attrs param to marker
nullpointer0x00 Feb 17, 2023
c3d40b5
add todos
nullpointer0x00 Feb 17, 2023
42fec61
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Feb 17, 2023
35657df
add required attribute param, add simple validate basic check, remove…
nullpointer0x00 Feb 21, 2023
03c164d
update handler tests
nullpointer0x00 Feb 21, 2023
ae2dcd6
inject name keeper into marker keeper, add initial normalize function
nullpointer0x00 Feb 21, 2023
61a6aa6
check error
nullpointer0x00 Feb 21, 2023
5e68385
make common cli method for parsing req attrs, normalize req attrs in …
nullpointer0x00 Feb 21, 2023
1503f11
add normalization test, allow wild cards at beginning (for now)
nullpointer0x00 Feb 21, 2023
37d0d44
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Feb 22, 2023
cc52539
move methods to new files, add requirement checks, add tests
nullpointer0x00 Feb 22, 2023
219c23d
add method docs
nullpointer0x00 Feb 22, 2023
e67c2c4
add test for contains required attributes that retrieves attrs from a…
nullpointer0x00 Feb 23, 2023
115b781
lint fix
nullpointer0x00 Feb 23, 2023
5cd9fd1
revert change
nullpointer0x00 Feb 23, 2023
8302ad3
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Feb 23, 2023
6ab364d
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Mar 1, 2023
5f7588b
Add marker checking function to sdk
nullpointer0x00 Mar 2, 2023
0b87846
if marker does not exist allow only should happen during tests, eat g…
nullpointer0x00 Mar 2, 2023
b8ff388
refactor send restrictions func to return only error if failure happens
nullpointer0x00 Mar 2, 2023
f15895b
use tmp cosmos-sdk tag
nullpointer0x00 Mar 2, 2023
fd4a929
update add genesis marker command
nullpointer0x00 Mar 2, 2023
4a88169
add tests, add additional logic
nullpointer0x00 Mar 6, 2023
be291b4
Update cosmos-sdk tag to move required attributes check to msg send a…
nullpointer0x00 Mar 7, 2023
c358b1b
remove enabled send calls
nullpointer0x00 Mar 7, 2023
a717ecb
remove unused method
nullpointer0x00 Mar 7, 2023
8010230
remove module account check, add comments
nullpointer0x00 Mar 7, 2023
0b59217
pass down granter attributes to function
nullpointer0x00 Mar 7, 2023
0ec79ce
add has access to context, check transfer access when has access not …
nullpointer0x00 Mar 9, 2023
f0c4547
refactor name, simplify comparison
nullpointer0x00 Mar 9, 2023
dd87a56
add allow access to adjusting circulation, add non restricted marker …
nullpointer0x00 Mar 9, 2023
6a64a61
add access allowed to proposal
nullpointer0x00 Mar 9, 2023
cee6b46
change input output coins to send coins, remove module address check …
nullpointer0x00 Mar 9, 2023
1cc1d20
add back send enabled setting, update tests for new gas usage
nullpointer0x00 Mar 14, 2023
68c0a44
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Mar 14, 2023
84c3d32
move module address setup, return error on get marker
nullpointer0x00 Mar 14, 2023
5678a66
edit test
nullpointer0x00 Mar 14, 2023
68505b5
add temp changes to error msg
nullpointer0x00 Mar 14, 2023
e2654b0
revert error msg text, update sim genesis
nullpointer0x00 Mar 15, 2023
9fc48bd
re-order init genesis with marker after bank module, add required att…
nullpointer0x00 Mar 15, 2023
7373467
fix tests to work with new genesis ordering
nullpointer0x00 Mar 15, 2023
b9e326c
refactor a few things
nullpointer0x00 Mar 16, 2023
be96693
Update tests
nullpointer0x00 Mar 16, 2023
6da0722
add changelog entry
nullpointer0x00 Mar 16, 2023
9a43b3a
fix struct field tag
nullpointer0x00 Mar 16, 2023
50cad8d
merge main, make proto-all
nullpointer0x00 Mar 16, 2023
f25fca5
remove setting of send enabled
nullpointer0x00 Mar 16, 2023
0b24716
remove send enabled code
nullpointer0x00 Mar 16, 2023
58a2988
update simulation to set send enabled
nullpointer0x00 Mar 16, 2023
0ad7da9
merge main
nullpointer0x00 Mar 16, 2023
1b7b7dc
fix change log
nullpointer0x00 Mar 17, 2023
0f3283c
remove unused bank store key from marker keeper
nullpointer0x00 Mar 17, 2023
5097d67
refactor proto number for req attributes, refactor command line arg p…
nullpointer0x00 Mar 21, 2023
6d62a01
remove unused value, add comments
nullpointer0x00 Mar 21, 2023
9df7288
update cosmos-sdk to tag v0.46.10-pio-3
nullpointer0x00 Mar 21, 2023
fa45422
merge main, resolve merge conflicts, update cmdline for req attributes
nullpointer0x00 Mar 22, 2023
8518057
change param order
nullpointer0x00 Mar 22, 2023
8157b90
add test named fields
nullpointer0x00 Mar 22, 2023
b7a15fe
change assert to EqualError
nullpointer0x00 Mar 22, 2023
13d1de9
add extra tests, fix missing logic
nullpointer0x00 Mar 22, 2023
bff2957
add additional test cases
nullpointer0x00 Mar 23, 2023
30cf260
add missing error msg assert
nullpointer0x00 Mar 23, 2023
1968c83
Merge branch 'main' into 1256-support-for-tokens-restricted-with-attr…
nullpointer0x00 Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* Add support for tokens restricted marker sends with required attributes [#1256](https://github.com/provenance-io/provenance/issues/1256))
* Allow markers to be configured to allow forced transfers [#1368](https://github.com/provenance-io/provenance/issues/1368).

### Improvements
Expand Down
11 changes: 6 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@ func New(
appCodec, keys[metadatatypes.StoreKey], app.GetSubspace(metadatatypes.ModuleName), app.AccountKeeper, app.AuthzKeeper,
)

app.MarkerKeeper = markerkeeper.NewKeeper(
appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper, app.TransferKeeper, keys[banktypes.StoreKey],
)

app.NameKeeper = namekeeper.NewKeeper(
appCodec, keys[nametypes.StoreKey], app.GetSubspace(nametypes.ModuleName),
)
Expand All @@ -475,6 +471,11 @@ func New(
appCodec, keys[attributetypes.StoreKey], app.GetSubspace(attributetypes.ModuleName), app.AccountKeeper, app.NameKeeper,
)

app.MarkerKeeper = markerkeeper.NewKeeper(
appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper, app.TransferKeeper, app.AttributeKeeper, app.NameKeeper,
)
app.BankKeeper.SetSendRestrictionsFunc(app.MarkerKeeper.AllowMarkerSend)

pioMessageRouter := MessageRouterFunc(func(msg sdk.Msg) baseapp.MsgServiceHandler {
return pioMsgFeesRouter.Handler(msg)
})
Expand Down Expand Up @@ -709,6 +710,7 @@ func New(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
markertypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand All @@ -723,7 +725,6 @@ func New(
quarantine.ModuleName,
sanction.ModuleName,

markertypes.ModuleName,
nametypes.ModuleName,
attributetypes.ModuleName,
metadatatypes.ModuleName,
Expand Down
1 change: 1 addition & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestExportAppStateAndValidators(t *testing.T) {
SupplyFixed: true,
AllowGovernanceControl: true,
AllowForcedTransfer: false,
RequiredAttributes: []string{},
}), "adding %q account", denom)
markerToAddr[denom] = markerAddr
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/provenanced/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func AddRootDomainAccountCmd(defaultNodeHome string) *cobra.Command {
// AddGenesisMarkerCmd configures a marker account and adds it to the list of genesis accounts
func AddGenesisMarkerCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-marker [coin] --manager [address_or_key_name] --access [grant][,[grant]] --escrow [coin][, [coin]] --finalize --activate --type [COIN]",
Use: "add-genesis-marker [coin] --manager [address_or_key_name] --access [grant][,[grant]] --escrow [coin][, [coin]] --finalize --activate --type [COIN] --required-attributes=attr.one,*.attr.two,...",
Short: "Adds a marker to genesis.json",
Long: `Adds a marker to genesis.json. The provided parameters must specify
the marker supply and denom as a coin. A managing account may be added as a key name or address. An accessgrant
Expand All @@ -312,7 +312,7 @@ a marker account is activated any unassigned marker supply must be provided as e
a manager address assigned that can activate the marker after genesis. Activated markers will have supply invariants
enforced immediately. An optional type flag can be provided or the default of COIN will be used.
`,
Example: fmt.Sprintf(`$ %[1]s add-genesis-marker 1000000000funcoins --manager validator --access withdraw --escrow 100funcoins --finalize --type COIN`, version.AppName),
Example: fmt.Sprintf(`$ %[1]s add-genesis-marker 1000000000funcoins --manager validator --access withdraw --escrow 100funcoins --finalize --type COIN --required-attributes=attr.one,*.attr.two,...`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand Down Expand Up @@ -414,6 +414,7 @@ enforced immediately. An optional type flag can be provided or the default of C
newMarkerFlags.SupplyFixed,
newMarkerFlags.AllowGovControl,
newMarkerFlags.AllowForceTransfer,
newMarkerFlags.RequiredAttributes,
)

if err = genAccount.Validate(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ MarkerAccount holds the marker configuration information in addition to a base a
| `supply_fixed` | [bool](#bool) | | A fixed supply will mint additional coin automatically if the total supply decreases below a set value. This may occur if the coin is burned or an account holding the coin is slashed. (default: true) |
| `allow_governance_control` | [bool](#bool) | | indicates that governance based control is allowed for this marker |
| `allow_forced_transfer` | [bool](#bool) | | Whether an admin can transfer restricted coins from a 3rd-party account without their signature. |
| `required_attributes` | [string](#string) | repeated | list of required attributes on restricted marker in order to send and receive transfers if sender does not have transfer authority |



Expand Down Expand Up @@ -1366,6 +1367,7 @@ AddMarkerProposal defines defines a governance proposal to create a new marker
| `access_list` | [AccessGrant](#provenance.marker.v1.AccessGrant) | repeated | |
| `supply_fixed` | [bool](#bool) | | |
| `allow_governance_control` | [bool](#bool) | | |
| `required_attributes` | [string](#string) | repeated | |



Expand Down Expand Up @@ -1921,6 +1923,7 @@ MsgAddFinalizeActivateMarkerRequest defines the Msg/AddFinalizeActivateMarker re
| `supply_fixed` | [bool](#bool) | | |
| `allow_governance_control` | [bool](#bool) | | |
| `allow_forced_transfer` | [bool](#bool) | | |
| `required_attributes` | [string](#string) | repeated | |



Expand Down Expand Up @@ -1954,6 +1957,7 @@ MsgAddMarkerRequest defines the Msg/AddMarker request type
| `supply_fixed` | [bool](#bool) | | |
| `allow_governance_control` | [bool](#bool) | | |
| `allow_forced_transfer` | [bool](#bool) | | |
| `required_attributes` | [string](#string) | repeated | |



Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ require (

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

replace github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.46.10-pio-1
replace github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.46.10-pio-3

// use informal system fork of tendermint in the interim until comet is ready. This matches what the SDK is using.
replace github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.26
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,8 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/provenance-io/cosmos-sdk v0.46.10-pio-1 h1:IhZz45StdsiyQ8D1cLbo4Ad7mZaMOXK6XBO7hHSBxxg=
github.com/provenance-io/cosmos-sdk v0.46.10-pio-1/go.mod h1:bBmYwqCTndsFE+QQs2zdIoZ3f86jEi0BmDVm6unmf3k=
github.com/provenance-io/cosmos-sdk v0.46.10-pio-3 h1:xoDLk++pxKDiPoMb6ch+qNzaIDfnHExJQH4mK6L5FLA=
github.com/provenance-io/cosmos-sdk v0.46.10-pio-3/go.mod h1:bBmYwqCTndsFE+QQs2zdIoZ3f86jEi0BmDVm6unmf3k=
github.com/provenance-io/ibc-go/v6 v6.1.0-pio-1 h1:2R9CS/FFGaOoPsdH+/8u+voFNmZqqkD6NuKsmnxMXLo=
github.com/provenance-io/ibc-go/v6 v6.1.0-pio-1/go.mod h1:CY3zh2HLfetRiW8LY6kVHMATe90Wj/UOoY8T6cuB0is=
github.com/provenance-io/wasmd v0.30.0-pio-1-rc3 h1:ZZf5LOERilqnr44J3DaD6KrwAY6NIprWvHcogu7FaSA=
Expand Down
168 changes: 168 additions & 0 deletions internal/handlers/bank_send_restriction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package handlers_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdksim "github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

piosimapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/internal/pioconfig"
attrtypes "github.com/provenance-io/provenance/x/attribute/types"
"github.com/provenance-io/provenance/x/marker/types"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

func TestBankSend(tt *testing.T) {
txFailureCode := uint32(1)
pioconfig.SetProvenanceConfig(sdk.DefaultBondDenom, 1) // set denom as stake and floor gas price as 1 stake.
priv1, _, addr1 := testdata.KeyTestPubAddr()
priv2, _, addr2 := testdata.KeyTestPubAddr()
priv3, _, addr3 := testdata.KeyTestPubAddr()
acct1 := authtypes.NewBaseAccount(addr1, priv1.PubKey(), 0, 0)
acct1Balance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000000)))
acct2 := authtypes.NewBaseAccount(addr2, priv2.PubKey(), 1, 0)
acct2Balance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000000)))
acct3 := authtypes.NewBaseAccount(addr3, priv3.PubKey(), 2, 0)

app := piosimapp.SetupWithGenesisAccounts(tt, "bank-restriction-testing",
[]authtypes.GenesisAccount{acct1, acct2, acct3},
banktypes.Balance{Address: addr1.String(), Coins: acct1Balance},
banktypes.Balance{Address: addr2.String(), Coins: acct2Balance},
)
ctx := app.BaseApp.NewContext(false, tmproto.Header{ChainID: "bank-restriction-testing"})
app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())

require.NoError(tt, app.NameKeeper.SetNameRecord(ctx, "some.kyc.provenance.io", addr1, false))
require.NoError(tt, app.AttributeKeeper.SetAttribute(ctx, attrtypes.NewAttribute("some.kyc.provenance.io", acct3.Address, attrtypes.AttributeType_Bytes, []byte{}), addr1))

nrMarkerDenom := "nonrestrictedmarker"
nrMarkerAcct := authtypes.NewBaseAccount(types.MustGetMarkerAddress(nrMarkerDenom), nil, 200, 0)
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, markertypes.NewMarkerAccount(nrMarkerAcct, sdk.NewInt64Coin(nrMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw}}}, markertypes.StatusProposed, markertypes.MarkerType_Coin, true, true, false, []string{})), "")

restrictedMarkerDenom := "restrictedmarker"
rMarkerAcct := authtypes.NewBaseAccount(types.MustGetMarkerAddress(restrictedMarkerDenom), nil, 300, 0)
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, markertypes.NewMarkerAccount(rMarkerAcct, sdk.NewInt64Coin(restrictedMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw, markertypes.Access_Transfer}}}, markertypes.StatusProposed, markertypes.MarkerType_RestrictedCoin, true, true, false, []string{})), "")

restrictedAttrMarkerDenom := "restrictedmarkerattr"
raMarkerAcct := authtypes.NewBaseAccount(types.MustGetMarkerAddress(restrictedAttrMarkerDenom), nil, 400, 0)
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, markertypes.NewMarkerAccount(raMarkerAcct, sdk.NewInt64Coin(restrictedAttrMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw, markertypes.Access_Transfer}}}, markertypes.StatusProposed, markertypes.MarkerType_RestrictedCoin, true, true, false, []string{"some.kyc.provenance.io"})), "")

// Check both account balances before we begin.
addr1beforeBalance := app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "1000000000stake", addr1beforeBalance, "addr1beforeBalance")
addr2beforeBalance := app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "1000000000stake", addr2beforeBalance, "addr2beforeBalance")

// send withdraw for coins
withdrawMsg := markertypes.NewMsgWithdrawRequest(addr1, addr1, nrMarkerDenom,
sdk.NewCoins(sdk.NewInt64Coin(nrMarkerDenom, 1000)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, withdrawMsg, abci.CodeTypeOK, "")
// Check both account balances before we begin.
addr1afterBalance := app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "1000nonrestrictedmarker,999850000stake", addr1afterBalance, "addr1afterBalance")

// send withdraw for coins
withdrawMsg = markertypes.NewMsgWithdrawRequest(addr1, addr1, restrictedMarkerDenom,
sdk.NewCoins(sdk.NewInt64Coin(restrictedMarkerDenom, 1000)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, withdrawMsg, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "1000nonrestrictedmarker,1000restrictedmarker,999700000stake", addr1afterBalance, "addr1afterBalance")

// send withdraw for coins
withdrawMsg = markertypes.NewMsgWithdrawRequest(addr1, addr1, restrictedAttrMarkerDenom,
sdk.NewCoins(sdk.NewInt64Coin(restrictedAttrMarkerDenom, 1000)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, withdrawMsg, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "1000nonrestrictedmarker,1000restrictedmarker,1000restrictedmarkerattr,999550000stake", addr1afterBalance, "addr1afterBalance")

// send restricted marker from account with transfer rights and no required attributes, expect success
sendRMarker := banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin(restrictedMarkerDenom, 100)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, sendRMarker, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "1000nonrestrictedmarker,900restrictedmarker,1000restrictedmarkerattr,999400000stake", addr1afterBalance, "addr1afterBalance")
addr2afterBalance := app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "100restrictedmarker,1000000000stake", addr2afterBalance, "addr2beforeBalance")

// send non restricted marker, expect success
sendRMarker = banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin(nrMarkerDenom, 100)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, sendRMarker, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "900nonrestrictedmarker,900restrictedmarker,1000restrictedmarkerattr,999250000stake", addr1afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "100nonrestrictedmarker,100restrictedmarker,1000000000stake", addr2afterBalance, "addr2beforeBalance")

sendNRMarker := banktypes.NewMsgSend(addr2, addr1, sdk.NewCoins(sdk.NewInt64Coin(nrMarkerDenom, 50)))
ConstructAndSendTx(tt, *app, ctx, acct2, priv2, sendNRMarker, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "950nonrestrictedmarker,900restrictedmarker,1000restrictedmarkerattr,999250000stake", addr1afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,100restrictedmarker,999850000stake", addr2afterBalance, "addr2beforeBalance")

// On a restricted coin without required attributes where the sender doesn't have TRANSFER permission.
sendRMarker = banktypes.NewMsgSend(addr2, addr1, sdk.NewCoins(sdk.NewInt64Coin(restrictedMarkerDenom, 100)))
ConstructAndSendTx(tt, *app, ctx, acct2, priv2, sendRMarker, txFailureCode, addr2.String()+" does not have transfer permissions")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "950nonrestrictedmarker,900restrictedmarker,1000restrictedmarkerattr,999250000stake", addr1afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,100restrictedmarker,999700000stake", addr2afterBalance, "addr2beforeBalance")

// On a restricted coin with required attributes from a sender that has TRANSFER permission, but the receiver doesn't have the required attributes.
sendRMarker = banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin(restrictedAttrMarkerDenom, 100)))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, sendRMarker, abci.CodeTypeOK, "")
addr1afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "950nonrestrictedmarker,900restrictedmarker,900restrictedmarkerattr,999100000stake", addr1afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,100restrictedmarker,100restrictedmarkerattr,999700000stake", addr2afterBalance, "addr2beforeBalance")

// On a restricted coin with required attributes from a sender that does not have TRANSFER permission, but the receiver DOES have the required attributes.
sendRMarker = banktypes.NewMsgSend(addr2, addr3, sdk.NewCoins(sdk.NewInt64Coin(restrictedAttrMarkerDenom, 25)))
ConstructAndSendTx(tt, *app, ctx, acct2, priv2, sendRMarker, abci.CodeTypeOK, "")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,100restrictedmarker,75restrictedmarkerattr,999550000stake", addr2afterBalance, "addr1afterBalance")
addr3afterBalance := app.BankKeeper.GetAllBalances(ctx, addr3).String()
assert.Equal(tt, "25restrictedmarkerattr", addr3afterBalance, "addr3beforeBalance")

// MsgTransfer Tests
// On a restricted coin with required attributes using an admin that has TRANSFER permission, but the receiver doesn't have the required attributes.
tranferRMarker := markertypes.NewMsgTransferRequest(addr1, addr1, addr2, sdk.NewInt64Coin(restrictedMarkerDenom, 25))
ConstructAndSendTx(tt, *app, ctx, acct1, priv1, tranferRMarker, abci.CodeTypeOK, "")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr1).String()
assert.Equal(tt, "950nonrestrictedmarker,875restrictedmarker,900restrictedmarkerattr,998950000stake", addr2afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,125restrictedmarker,75restrictedmarkerattr,999550000stake", addr2afterBalance, "addr2beforeBalance")

// On a restricted coin with required attributes using an admin that does not have TRANSFER permission, but the receiver DOES have the required attributes.
tranferRAMarker := markertypes.NewMsgTransferRequest(addr2, addr2, addr3, sdk.NewInt64Coin(restrictedAttrMarkerDenom, 25))
ConstructAndSendTx(tt, *app, ctx, acct2, priv2, tranferRAMarker, txFailureCode, addr2.String()+" is not allowed to broker transfers")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String()
assert.Equal(tt, "50nonrestrictedmarker,125restrictedmarker,75restrictedmarkerattr,999400000stake", addr2afterBalance, "addr1afterBalance")
addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr3).String()
assert.Equal(tt, "25restrictedmarkerattr", addr3afterBalance, "addr3beforeBalance")
}

func ConstructAndSendTx(tt *testing.T, app piosimapp.App, ctx sdk.Context, acct *authtypes.BaseAccount, priv cryptotypes.PrivKey, msg sdk.Msg, expectedCode uint32, expectedError string) {
encCfg := sdksim.MakeTestEncodingConfig()
fees := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(NewTestGasLimit())))
acct = app.AccountKeeper.GetAccount(ctx, acct.GetAddress()).(*authtypes.BaseAccount)
txBytes, err := SignTxAndGetBytes(NewTestGasLimit(), fees, encCfg, priv.PubKey(), priv, *acct, ctx.ChainID(), msg)
require.NoError(tt, err, "SignTxAndGetBytes")
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.Equal(tt, expectedCode, res.Code, "res=%+v", res)
if len(expectedError) > 0 {
require.Contains(tt, res.Log, expectedError, "DeliverTx result.Log")
}
}
Loading