diff --git a/internal/handlers/bank_send_restriction_test.go b/internal/handlers/bank_send_restriction_test.go index b4a48a4d90..216d8ab8f4 100644 --- a/internal/handlers/bank_send_restriction_test.go +++ b/internal/handlers/bank_send_restriction_test.go @@ -1,6 +1,7 @@ package handlers_test import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -163,7 +164,9 @@ func TestBankSend(tt *testing.T) { // 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") + expErr := fmt.Sprintf("%s does not have ACCESS_TRANSFER on restrictedmarkerattr marker (%s)", + addr2.String(), raMarkerAcct.GetAddress().String()) + ConstructAndSendTx(tt, *app, ctx, acct2, priv2, tranferRAMarker, txFailureCode, expErr) addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr2).String() assert.Equal(tt, "50nonrestrictedmarker,125restrictedmarker,75restrictedmarkerattr,999400000stake", addr2afterBalance, "addr1afterBalance") addr2afterBalance = app.BankKeeper.GetAllBalances(ctx, addr3).String() diff --git a/x/marker/handler_test.go b/x/marker/handler_test.go index acd3091c6a..a3b948aa28 100644 --- a/x/marker/handler_test.go +++ b/x/marker/handler_test.go @@ -97,6 +97,13 @@ func (s *HandlerTestSuite) containsMessage(result *sdk.Result, msg proto.Message return false } +// noAccessErr creates an expected error message for an address not having access on a marker. +func (s *HandlerTestSuite) noAccessErr(addr string, role types.Access, denom string) string { + mAddr, err := types.MarkerAddress(denom) + s.Require().NoError(err, "MarkerAddress(%q)", denom) + return fmt.Sprintf("%s does not have %s on %s marker (%s)", addr, role, denom, mAddr) +} + type CommonTest struct { name string msg sdk.Msg @@ -460,9 +467,9 @@ func (s *HandlerTestSuite) TestMsgAddFinalizeActivateMarkerRequest() { expectedEvent: types.NewEventMarkerMint("1000", denom, s.user1), }, { - name: "should fail to burn denom, user doesn't have permissions", + name: "should fail to burn denom, user doesn't have permissions", msg: types.NewMsgBurnRequest(s.user1Addr, sdk.NewInt64Coin(denom, 50)), - errorMsg: fmt.Sprintf("%s does not have ACCESS_BURN on hotdog markeraccount: invalid request", s.user1), + errorMsg: s.noAccessErr(s.user1, types.Access_Burn, denom) + ": invalid request", }, } s.runTests(cases) @@ -543,7 +550,7 @@ func (s *HandlerTestSuite) TestMsgSetAccountDataRequest() { Value: "This is some unrestricted coin data. This won't get used though.", Signer: s.user1, }, - errorMsg: s.user1 + " does not have deposit access for " + denomU + " marker", + errorMsg: s.noAccessErr(s.user1, types.Access_Deposit, denomU), }, { name: "should successfully set account data on restricted marker via gov prop", @@ -570,7 +577,7 @@ func (s *HandlerTestSuite) TestMsgSetAccountDataRequest() { Value: "This is some restricted coin data. This won't get used though.", Signer: s.user1, }, - errorMsg: s.user1 + " does not have deposit access for " + denomR + " marker", + errorMsg: s.noAccessErr(s.user1, types.Access_Deposit, denomR), }, } s.runTests(tests) diff --git a/x/marker/keeper/keeper_test.go b/x/marker/keeper/keeper_test.go index 5d606a4285..24b3669aa7 100644 --- a/x/marker/keeper/keeper_test.go +++ b/x/marker/keeper/keeper_test.go @@ -621,6 +621,8 @@ func TestTransferCoin(t *testing.T) { addrManager := sdk.AccAddress("manager_____________") addrTransOnly := sdk.AccAddress("transfer_only_______") + addrForceTransOnly := sdk.AccAddress("force_transfer_only_") + addrTransAndForce := sdk.AccAddress("transfer_and_force__") addrTransDepWithdraw := sdk.AccAddress("xfer_dep_withdraw___") addrNoTrans := sdk.AccAddress("all_but_transfer____") addrSeq0 := sdk.AccAddress("addr_w_sequence_zero") @@ -640,11 +642,11 @@ func TestTransferCoin(t *testing.T) { addr1, addr2, addr3, addr4, } - coinDenom := "normalcoin" - restrictedDenom := "restrictedcoin" - onlyDepositDenom := "onlydepositcoin" - onlyWithdrawDenom := "onlywithdrawcoin" - forceTransDenom := "jedicoin" + denomCoin := "normalcoin" + denomRestricted := "restrictedcoin" + denomOnlyDeposit := "onlydepositcoin" + denomOnlyWithdraw := "onlywithdrawcoin" + denomForceTrans := "jedicoin" allAccessExcept := func(addr sdk.AccAddress, perms ...types.Access) types.AccessGrant { rv := types.AccessGrant{ @@ -683,7 +685,7 @@ func TestTransferCoin(t *testing.T) { require.NoError(t, err, "MarkerAddress(%q)", denom) return rv } - fundAcct := func(denom string, addr sdk.AccAddress) { + fundAcct := func(addr sdk.AccAddress, denom string) { fundAmt := sdk.NewCoins(sdk.NewInt64Coin(denom, 1_000_000)) err := app.MarkerKeeper.WithdrawCoins(ctx, addrManager, addr, denom, fundAmt) require.NoError(t, err, "WithdrawCoins %s to %q", fundAmt, string(addr)) @@ -722,7 +724,7 @@ func TestTransferCoin(t *testing.T) { require.NoError(t, err, "AddFinalizeAndActivateMarker %q", denom) for _, fundAddr := range addrsToFund { - fundAcct(denom, fundAddr) + fundAcct(fundAddr, denom) } return addr @@ -750,6 +752,11 @@ func TestTransferCoin(t *testing.T) { res.GroupPolicyAddress, string(admin)) return rv } + noAccessErr := func(addr sdk.AccAddress, role types.Access, denom string) string { + mAddr, err := types.MarkerAddress(denom) + require.NoError(t, err, "MarkerAddress(%q)", denom) + return fmt.Sprintf("%s does not have %s on %s marker (%s)", addr, role, denom, mAddr) + } for _, addr := range seq1Addrs { setAcc(addr, 1) @@ -759,53 +766,61 @@ func TestTransferCoin(t *testing.T) { addrGroup := createGroup(addrManager) addrsToFund = append(addrsToFund, addrGroup) - coinMarker := &types.MarkerAccount{ - AccessControl: []types.AccessGrant{allAccessExcept(addrManager, types.Access_Transfer)}, + markerCoin := &types.MarkerAccount{ + AccessControl: []types.AccessGrant{allAccessExcept(addrManager, types.Access_Transfer, types.Access_ForceTransfer)}, MarkerType: types.MarkerType_Coin, SupplyFixed: true, AllowGovernanceControl: true, AllowForcedTransfer: false, } - coinAddr := setupMarker(coinDenom, coinMarker) + markerAddrCoin := setupMarker(denomCoin, markerCoin) - restrictedMarker := &types.MarkerAccount{ + markerRestricted := &types.MarkerAccount{ AccessControl: []types.AccessGrant{ accessOnly(addrTransOnly, types.Access_Transfer), + accessOnly(addrForceTransOnly, types.Access_ForceTransfer), + accessOnly(addrTransAndForce, types.Access_Transfer, types.Access_ForceTransfer), accessOnly(addrTransDepWithdraw, types.Access_Transfer), - allAccessExcept(addrNoTrans, types.Access_Transfer), + allAccessExcept(addrNoTrans, types.Access_Transfer, types.Access_ForceTransfer), }, SupplyFixed: true, AllowGovernanceControl: true, AllowForcedTransfer: false, } - setupMarker(restrictedDenom, restrictedMarker) + setupMarker(denomRestricted, markerRestricted) - onlyDepositMarker := &types.MarkerAccount{ + markerOnlyDep := &types.MarkerAccount{ AccessControl: []types.AccessGrant{accessOnly(addrTransDepWithdraw, types.Access_Deposit)}, SupplyFixed: true, AllowGovernanceControl: true, AllowForcedTransfer: false, } - onlyDepositAddr := setupMarker(onlyDepositDenom, onlyDepositMarker) + markerAddrOnlyDep := setupMarker(denomOnlyDeposit, markerOnlyDep) - onlyWithdrawMarker := &types.MarkerAccount{ + markerOnlyWithdraw := &types.MarkerAccount{ AccessControl: []types.AccessGrant{accessOnly(addrTransDepWithdraw, types.Access_Withdraw)}, SupplyFixed: true, AllowGovernanceControl: true, AllowForcedTransfer: false, } - onlyWithdrawAddr := setupMarker(onlyWithdrawDenom, onlyWithdrawMarker) + markerAddrOnlyWithdraw := setupMarker(denomOnlyWithdraw, markerOnlyWithdraw) - forceTransMarker := &types.MarkerAccount{ - AccessControl: []types.AccessGrant{accessOnly(addrTransOnly, types.Access_Transfer)}, + markerForceTrans := &types.MarkerAccount{ + AccessControl: []types.AccessGrant{ + accessOnly(addrTransDepWithdraw, types.Access_Transfer), + accessOnly(addrTransOnly, types.Access_Transfer), + accessOnly(addrForceTransOnly, types.Access_ForceTransfer), + accessOnly(addrTransAndForce, types.Access_Transfer, types.Access_ForceTransfer), + }, SupplyFixed: true, AllowGovernanceControl: true, AllowForcedTransfer: true, } - forceTransAddr := setupMarker(forceTransDenom, forceTransMarker) + setupMarker(denomForceTrans, markerForceTrans) - // The only-withdraw marker needs to have some restricted coin, because, reasons. - fundAcct(restrictedDenom, onlyWithdrawAddr) + // The only-withdraw marker needs to have some coins, because, reasons (needed for test cases). + fundAcct(markerAddrOnlyWithdraw, denomRestricted) + fundAcct(markerAddrOnlyWithdraw, denomForceTrans) tests := []struct { name string @@ -830,47 +845,47 @@ func TestTransferCoin(t *testing.T) { from: addr1, to: addr2, admin: addr3, - amount: sdk.NewInt64Coin(coinDenom, 12), + amount: sdk.NewInt64Coin(denomCoin, 12), expErr: "marker type is not restricted_coin, brokered transfer not supported", }, { - name: "admin does not have transfer", + name: "admin does not have transfer or force transfer", from: addr1, to: addr2, admin: addrNoTrans, - amount: sdk.NewInt64Coin(restrictedDenom, 8), - expErr: addrNoTrans.String() + " is not allowed to broker transfers", + amount: sdk.NewInt64Coin(denomRestricted, 8), + expErr: noAccessErr(addrNoTrans, types.Access_Transfer, denomRestricted), }, { name: "going to restricted: admin does not have deposit", from: addrTransOnly, - to: onlyDepositAddr, + to: markerAddrOnlyDep, admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 14), - expErr: addrTransOnly.String() + " does not have deposit access on " + onlyDepositAddr.String() + " (" + onlyDepositDenom + ")", + amount: sdk.NewInt64Coin(denomRestricted, 14), + expErr: noAccessErr(addrTransOnly, types.Access_Deposit, denomOnlyDeposit), }, { name: "going to restricted: admin has deposit", from: addrTransDepWithdraw, - to: onlyDepositAddr, + to: markerAddrOnlyDep, admin: addrTransDepWithdraw, - amount: sdk.NewInt64Coin(restrictedDenom, 9), + amount: sdk.NewInt64Coin(denomRestricted, 9), }, { name: "going to unrestricted", from: addrTransOnly, - to: coinAddr, + to: markerAddrCoin, admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 17), + amount: sdk.NewInt64Coin(denomRestricted, 17), }, { name: "admin not from: no force transfer: no authz", authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerNoAuth(), from: addr4, to: addr3, - admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 11), - expErr: addrTransOnly.String() + " account has not been granted authority to withdraw from " + addr4.String() + " account", + admin: addrTransAndForce, + amount: sdk.NewInt64Coin(denomRestricted, 11), + expErr: addrTransAndForce.String() + " account has not been granted authority to withdraw from " + addr4.String() + " account", }, { name: "admin not from: no force transfer: with authz", @@ -878,46 +893,78 @@ func TestTransferCoin(t *testing.T) { from: addr3, to: addr1, admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 23), + amount: sdk.NewInt64Coin(denomRestricted, 23), }, { - name: "admin not from: no force transfer: from marker: no withdraw", + name: "admin not from: no force transfer: from marker: with withdraw", authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerSuccess(), - from: forceTransAddr, + from: markerAddrOnlyWithdraw, to: addr2, + admin: addrTransDepWithdraw, + amount: sdk.NewInt64Coin(denomRestricted, 2), + }, + { + name: "admin not from: no force transfer access: no authz", + authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerNoAuth(), + from: addr4, + to: addr3, admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 33), - expErr: addrTransOnly.String() + " does not have withdraw permission on " + forceTransAddr.String() + " (" + forceTransDenom + ")", + amount: sdk.NewInt64Coin(denomForceTrans, 11), + expErr: addrTransOnly.String() + " account has not been granted authority to withdraw from " + addr4.String() + " account", }, { - name: "admin not from: no force transfer: from marker: with withdraw", + name: "admin not from: no force transfer access: with authz", authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerSuccess(), - from: onlyWithdrawAddr, + from: addr3, + to: addr1, + admin: addrTransOnly, + amount: sdk.NewInt64Coin(denomForceTrans, 23), + }, + { + name: "admin not from: no force transfer access: from marker: with withdraw", + authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerSuccess(), + from: markerAddrOnlyWithdraw, to: addr2, admin: addrTransDepWithdraw, - amount: sdk.NewInt64Coin(restrictedDenom, 2), + amount: sdk.NewInt64Coin(denomForceTrans, 2), + }, + { + name: "admin not from: force transfer okay: no force transfer access", + authzKeeper: NewMockAuthzKeeper().WithAuthzHandlerNoAuth(), + from: addr4, + to: addr1, + admin: addrTransOnly, + amount: sdk.NewInt64Coin(denomForceTrans, 19), + expErr: addrTransOnly.String() + " account has not been granted authority to withdraw from " + addr4.String() + " account", + }, + { + name: "admin not from: force transfer okay: only force access", + from: addr4, + to: addr1, + admin: addrForceTransOnly, + amount: sdk.NewInt64Coin(denomForceTrans, 20), }, { name: "admin not from: force transfer: from is a group account", from: addrGroup, to: addr3, - admin: addrTransOnly, - amount: sdk.NewInt64Coin(forceTransDenom, 15), + admin: addrTransAndForce, + amount: sdk.NewInt64Coin(denomForceTrans, 15), }, { name: "admin not from: force transfer: from account has sequence zero", from: addrSeq0, to: addr1, - admin: addrTransOnly, - amount: sdk.NewInt64Coin(forceTransDenom, 7), + admin: addrTransAndForce, + amount: sdk.NewInt64Coin(denomForceTrans, 7), expErr: "funds are not allowed to be removed from " + addrSeq0.String(), }, { name: "admin not from: force transfer: from okay account", from: addr1, to: addr2, - admin: addrTransOnly, - amount: sdk.NewInt64Coin(forceTransDenom, 41), + admin: addrTransAndForce, + amount: sdk.NewInt64Coin(denomForceTrans, 41), }, { name: "to blocked account", @@ -925,7 +972,7 @@ func TestTransferCoin(t *testing.T) { from: addrTransOnly, to: addr3, admin: addrTransOnly, - amount: sdk.NewInt64Coin(restrictedDenom, 57), + amount: sdk.NewInt64Coin(denomRestricted, 57), expErr: addr3.String() + " is not allowed to receive funds", }, { @@ -933,8 +980,8 @@ func TestTransferCoin(t *testing.T) { bankKeeper: NewWrappedBankKeeper().WithSendCoinsErrs("nope, not gonna allow that"), from: addr1, to: addr2, - admin: addrTransOnly, - amount: sdk.NewInt64Coin(forceTransDenom, 48), + admin: addrForceTransOnly, + amount: sdk.NewInt64Coin(denomForceTrans, 48), expErr: "nope, not gonna allow that", }, } @@ -969,34 +1016,6 @@ func TestTransferCoin(t *testing.T) { var expEvents sdk.Events if len(tc.expErr) == 0 { expEvents = sdk.Events{ - { - Type: "coin_spent", - Attributes: []abci.EventAttribute{ - {Key: []byte("spender"), Value: []byte(tc.from.String())}, - {Key: []byte("amount"), Value: []byte(tc.amount.String())}, - }, - }, - { - Type: "coin_received", - Attributes: []abci.EventAttribute{ - {Key: []byte("receiver"), Value: []byte(tc.to.String())}, - {Key: []byte("amount"), Value: []byte(tc.amount.String())}, - }, - }, - { - Type: "transfer", - Attributes: []abci.EventAttribute{ - {Key: []byte("recipient"), Value: []byte(tc.to.String())}, - {Key: []byte("sender"), Value: []byte(tc.from.String())}, - {Key: []byte("amount"), Value: []byte(tc.amount.String())}, - }, - }, - { - Type: "message", - Attributes: []abci.EventAttribute{ - {Key: []byte("sender"), Value: []byte(tc.from.String())}, - }, - }, { Type: "provenance.marker.v1.EventMarkerTransfer", Attributes: []abci.EventAttribute{ @@ -1019,7 +1038,7 @@ func TestTransferCoin(t *testing.T) { require.NotPanics(t, testFunc, "TransferCoin") assertions.AssertErrorValue(t, err, tc.expErr, "TransferCoin error") actEvents := em.Events() - assertions.AssertEqualEvents(t, expEvents, actEvents, "events emitted during TransferCoin") + assertions.AssertEventsContains(t, expEvents, actEvents, "events emitted during TransferCoin") actFromBal := app.BankKeeper.GetAllBalances(ctx, tc.from) actToBal := app.BankKeeper.GetAllBalances(ctx, tc.to) @@ -1259,7 +1278,7 @@ func TestMarkerFeeGrant(t *testing.T) { app.AccountKeeper.SetAccount(ctx, mac) existingSupply := sdk.NewCoin("testcoin", sdk.NewInt(10000)) - require.NoError(t, testutil.FundAccount(app.BankKeeper, ctx, user, sdk.NewCoins(existingSupply)), "funding accont") + require.NoError(t, testutil.FundAccount(app.BankKeeper, types.WithBypass(ctx), user, sdk.NewCoins(existingSupply)), "funding accont") allowance, err := types.NewMsgGrantAllowance( "testcoin", diff --git a/x/marker/keeper/msg_server_test.go b/x/marker/keeper/msg_server_test.go index e4a692bc34..703f0a821c 100644 --- a/x/marker/keeper/msg_server_test.go +++ b/x/marker/keeper/msg_server_test.go @@ -551,7 +551,7 @@ func (s *MsgServerTestSuite) TestUpdateSendDenyList() { { name: "should fail, signer does not have admin access", msg: types.MsgUpdateSendDenyListRequest{Denom: rMarkerDenom, Authority: notAuthUser.String(), RemoveDeniedAddresses: []string{}, AddDeniedAddresses: []string{}}, - expErr: "cosmos1ku2jzvpkt4ffxxaajyk2r88axk9cr5jqlthcm4 does not have transfer authority for restricted-marker marker", + expErr: fmt.Sprintf("%s does not have %s on %s marker (%s)", notAuthUser, types.Access_Transfer, rMarkerDenom, rMarkerAcct.Address), }, { name: "should fail, gov not enabled for restricted marker", diff --git a/x/marker/keeper/send_restrictions_test.go b/x/marker/keeper/send_restrictions_test.go index cae628adf5..14816247b5 100644 --- a/x/marker/keeper/send_restrictions_test.go +++ b/x/marker/keeper/send_restrictions_test.go @@ -121,7 +121,7 @@ func TestSendRestrictionFn(t *testing.T) { newMarker := func(denom string, markerType types.MarkerType, reqAttrs []string) *types.MarkerAccount { return createActiveMarker(newMarkerAcc(denom, markerType, reqAttrs)) } - newPendingMarker := func(denom string, markerType types.MarkerType, reqAttrs []string) *types.MarkerAccount { + newProposedMarker := func(denom string, markerType types.MarkerType, reqAttrs []string) *types.MarkerAccount { rv := newMarkerAcc(denom, markerType, reqAttrs) err := app.MarkerKeeper.AddMarkerAccount(ctx, rv) require.NoError(t, err, "AddMarkerAccount(%s)", denom) @@ -157,8 +157,14 @@ func TestSendRestrictionFn(t *testing.T) { rDenom3Attrs := "restrictedmarkerreqattributes5" newMarker(rDenom3Attrs, restricted, []string{"kyc.provenance.io", "not-kyc.provenance.io", "foo.provenance.io"}) - rDenomPending := "stillpending" - rMarkerPending := newPendingMarker(rDenomPending, restricted, nil) + rDenomProposed := "stillproposed" + rMarkerProposed := newProposedMarker(rDenomProposed, restricted, nil) + + noAccessErr := func(addr sdk.AccAddress, role types.Access, denom string) string { + mAddr, err := types.MarkerAddress(denom) + require.NoError(t, err, "MarkerAddress(%q)", denom) + return fmt.Sprintf("%s does not have %s on %s marker (%s)", addr, role, denom, mAddr) + } testCases := []struct { name string @@ -312,34 +318,32 @@ func TestSendRestrictionFn(t *testing.T) { addrWithAttrsStr, rDenom1AttrNoOneHas), }, { - name: "send to marker from account without deposit", - from: addrWithAttrs, - to: rMarkerNoAttr.GetAddress(), - amt: cz(c(1, rDenomNoAttr)), - expErr: fmt.Sprintf("%s does not have deposit access for %s (%s)", - addrWithAttrsStr, rMarkerNoAttr.GetAddress().String(), rDenomNoAttr), + name: "send to marker from account without deposit", + from: addrWithAttrs, + to: rMarkerNoAttr.GetAddress(), + amt: cz(c(1, rDenomNoAttr)), + expErr: noAccessErr(addrWithAttrs, types.Access_Deposit, rDenomNoAttr), }, { name: "send to marker from account with deposit but no transfer", from: addrWithDeposit, to: rMarkerNoAttr.GetAddress(), amt: cz(c(1, rDenomNoAttr)), - expErr: addrWithDeposit.String() + " does not have transfer access for " + rDenomNoAttr, + expErr: noAccessErr(addrWithDeposit, types.Access_Transfer, rDenomNoAttr), }, { - name: "send to another marker with transfer on denom but no deposit on to", - from: addrWithTransfer, - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenomNoAttr)), - expErr: fmt.Sprintf("%s does not have deposit access for %s (%s)", - addrWithTransfer, rMarker1Attr.GetAddress().String(), rDenom1Attr), + name: "send to another marker with transfer on denom but no deposit on to", + from: addrWithTransfer, + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenomNoAttr)), + expErr: noAccessErr(addrWithTransfer, types.Access_Deposit, rDenom1Attr), }, { name: "send to another marker without transfer on denom but with deposit on to", from: addrWithDeposit, to: rMarker1Attr.GetAddress(), amt: cz(c(1, rDenomNoAttr)), - expErr: addrWithDeposit.String() + " does not have transfer access for " + rDenomNoAttr, + expErr: noAccessErr(addrWithDeposit, types.Access_Transfer, rDenomNoAttr), }, { name: "send to another marker with transfer on denom and deposit on to", @@ -356,26 +360,25 @@ func TestSendRestrictionFn(t *testing.T) { expErr: "", }, { - name: "to a marker from addr with bypass but no deposit", - from: addrWithBypassNoDep, - to: rMarkerNoAttr.GetAddress(), - amt: cz(c(1, rDenomNoAttr)), - expErr: fmt.Sprintf("%s does not have deposit access for %s (%s)", - addrWithBypassNoDep, rMarkerNoAttr.GetAddress().String(), rDenomNoAttr), + name: "to a marker from addr with bypass but no deposit", + from: addrWithBypassNoDep, + to: rMarkerNoAttr.GetAddress(), + amt: cz(c(1, rDenomNoAttr)), + expErr: noAccessErr(addrWithBypassNoDep, types.Access_Deposit, rDenomNoAttr), }, { name: "to a marker with req attrs from an addr with bypass", from: addrWithBypass, to: rMarker1Attr.GetAddress(), amt: cz(c(1, rDenom1Attr)), - expErr: addrWithBypass.String() + " does not have transfer access for " + rDenom1Attr, + expErr: noAccessErr(addrWithBypass, types.Access_Transfer, rDenom1Attr), }, { name: "to marker without req attrs from addr with bypass", from: addrWithBypass, to: rMarkerNoAttr.GetAddress(), amt: cz(c(1, rDenomNoAttr)), - expErr: addrWithBypass.String() + " does not have transfer access for " + rDenomNoAttr, + expErr: noAccessErr(addrWithBypass, types.Access_Transfer, rDenomNoAttr), }, { name: "no req attrs from addr with bypass", @@ -447,22 +450,22 @@ func TestSendRestrictionFn(t *testing.T) { from: rMarkerNoAttr.GetAddress(), to: addrWithAttrs, amt: cz(c(2, rDenomNoAttr)), - expErr: addrWithTransfer.String() + " does not have withdraw access for " + rMarkerNoAttr.GetAddress().String() + " (" + rDenomNoAttr + ")", + expErr: noAccessErr(addrWithTransfer, types.Access_Withdraw, rDenomNoAttr), }, { name: "from marker: withdraw marker funds from inactive marker", ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranWithdraw)), - from: rMarkerPending.GetAddress(), + from: rMarkerProposed.GetAddress(), to: addrWithAttrs, - amt: cz(c(2, rDenomNoAttr), c(1, rDenomPending), c(5, rDenom3Attrs)), - expErr: fmt.Sprintf("cannot withdraw marker created coins (%s) from marker %s (%s) that is not in active status (proposed)", - cz(c(2, rDenomNoAttr), c(1, rDenomPending), c(5, rDenom3Attrs)), rMarkerPending.GetAddress().String(), rDenomPending, + amt: cz(c(2, rDenomNoAttr), c(1, rDenomProposed), c(5, rDenom3Attrs)), + expErr: fmt.Sprintf("cannot withdraw %s from %s marker (%s): marker status (proposed) is not active", + c(1, rDenomProposed), rDenomProposed, rMarkerProposed.GetAddress(), ), }, { name: "from marker: withdraw non-marker funds from inactive marker", ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranWithdraw)), - from: rMarkerPending.GetAddress(), + from: rMarkerProposed.GetAddress(), to: addrWithAttrs, amt: cz(c(2, rDenomNoAttr), c(5, rDenom3Attrs)), }, @@ -488,54 +491,44 @@ func TestSendRestrictionFn(t *testing.T) { amt: cz(c(1, rDenomNoAttr)), }, { - name: "from marker to marker: admin only has transfer", - ctx: ctxP(types.WithTransferAgent(ctx, addrWithTransfer)), - from: rMarkerNoAttr.GetAddress(), - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenom1AttrNoOneHas)), - expErr: addrWithTransfer.String() + " does not have withdraw access for " + - rMarkerNoAttr.GetAddress().String() + - " (" + rDenomNoAttr + ")", + name: "from marker to marker: admin only has transfer", + ctx: ctxP(types.WithTransferAgent(ctx, addrWithTransfer)), + from: rMarkerNoAttr.GetAddress(), + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenom1AttrNoOneHas)), + expErr: noAccessErr(addrWithTransfer, types.Access_Withdraw, rDenomNoAttr), }, { - name: "from marker to marker: admin only has deposit", - ctx: ctxP(types.WithTransferAgent(ctx, addrWithDeposit)), - from: rMarkerNoAttr.GetAddress(), - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenom1AttrNoOneHas)), - expErr: addrWithDeposit.String() + " does not have withdraw access for " + - rMarkerNoAttr.GetAddress().String() + - " (" + rDenomNoAttr + ")", + name: "from marker to marker: admin only has deposit", + ctx: ctxP(types.WithTransferAgent(ctx, addrWithDeposit)), + from: rMarkerNoAttr.GetAddress(), + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenom1AttrNoOneHas)), + expErr: noAccessErr(addrWithDeposit, types.Access_Withdraw, rDenomNoAttr), }, { - name: "from marker to marker: admin only has withdraw", - ctx: ctxP(types.WithTransferAgent(ctx, addrWithWithdraw)), - from: rMarkerNoAttr.GetAddress(), - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenom1AttrNoOneHas)), - expErr: addrWithWithdraw.String() + " does not have deposit access for " + - rMarker1Attr.GetAddress().String() + - " (" + rDenom1Attr + ")", + name: "from marker to marker: admin only has withdraw", + ctx: ctxP(types.WithTransferAgent(ctx, addrWithWithdraw)), + from: rMarkerNoAttr.GetAddress(), + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenom1AttrNoOneHas)), + expErr: noAccessErr(addrWithWithdraw, types.Access_Deposit, rDenom1Attr), }, { - name: "from marker to marker: admin only has transfer and deposit", - ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranDep)), - from: rMarkerNoAttr.GetAddress(), - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenom1AttrNoOneHas)), - expErr: addrWithTranDep.String() + " does not have withdraw access for " + - rMarkerNoAttr.GetAddress().String() + - " (" + rDenomNoAttr + ")", + name: "from marker to marker: admin only has transfer and deposit", + ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranDep)), + from: rMarkerNoAttr.GetAddress(), + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenom1AttrNoOneHas)), + expErr: noAccessErr(addrWithTranDep, types.Access_Withdraw, rDenomNoAttr), }, { - name: "from marker to marker: admin only has transfer and withdraw", - ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranWithdraw)), - from: rMarkerNoAttr.GetAddress(), - to: rMarker1Attr.GetAddress(), - amt: cz(c(1, rDenom1AttrNoOneHas)), - expErr: addrWithTranWithdraw.String() + " does not have deposit access for " + - rMarker1Attr.GetAddress().String() + - " (" + rDenom1Attr + ")", + name: "from marker to marker: admin only has transfer and withdraw", + ctx: ctxP(types.WithTransferAgent(ctx, addrWithTranWithdraw)), + from: rMarkerNoAttr.GetAddress(), + to: rMarker1Attr.GetAddress(), + amt: cz(c(1, rDenom1AttrNoOneHas)), + expErr: noAccessErr(addrWithTranWithdraw, types.Access_Deposit, rDenom1Attr), }, { name: "from marker to marker: admin only has deposit and withdraw", @@ -543,7 +536,7 @@ func TestSendRestrictionFn(t *testing.T) { from: rMarker1Attr.GetAddress(), to: rMarker2Attrs.GetAddress(), amt: cz(c(1, rDenom1Attr)), - expErr: addrWithDepWithdraw.String() + " does not have transfer access for " + rDenom1Attr, + expErr: noAccessErr(addrWithDepWithdraw, types.Access_Transfer, rDenom1Attr), }, { name: "from marker to marker: admin has transfer and deposit and withdraw",