Skip to content

Commit

Permalink
[1834]: Fix some comments in the mocks, add a unit test making sure f…
Browse files Browse the repository at this point in the history
…orce-transfer access is ignored in the send restriction, and add force transfer to a couple access unit tests.
  • Loading branch information
SpicyLemon committed Feb 10, 2024
1 parent 2e3f0db commit f31acf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions x/marker/keeper/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ func NewWrappedAttrKeeper() *WrappedAttrKeeper {
return &WrappedAttrKeeper{}
}

// WithParent sets the parent bank keeper for this wrapping.
// WithParent sets the parent attr keeper for this wrapping.
func (w *WrappedAttrKeeper) WithParent(attrKeeper types.AttrKeeper) *WrappedAttrKeeper {
w.AttrKeeper = attrKeeper
return w
}

// WithGetAllAttributesAddrErrs adds the provided error strings to the list of errors that will be
// returned by GetAllAttributesAddr. A non-empty entry will be returned as an error (when its time comes).
// An empty entry (or if there aren't any entries left when SendCoins is called) will
// result in the parent's SendCoins function being called and returned.
// An empty entry (or if there aren't any entries left when GetAllAttributesAddr is called) will
// result in the parent's GetAllAttributesAddr function being called and returned.
func (w *WrappedAttrKeeper) WithGetAllAttributesAddrErrs(errs ...string) *WrappedAttrKeeper {
w.GetAllAttributesAddrErrs = append(w.GetAllAttributesAddrErrs, errs...)
return w
Expand Down
9 changes: 9 additions & 0 deletions x/marker/keeper/send_restrictions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestSendRestrictionFn(t *testing.T) {

addrWithoutAttrs := sdk.AccAddress("addr_without_attribs")
addrWithTransfer := sdk.AccAddress("addr_with_transfer__")
addrWithForceTransfer := sdk.AccAddress("addr_with_force_tran")
addrWithDeposit := sdk.AccAddress("addrWithDeposit_____")
addrWithWithdraw := sdk.AccAddress("addrWithWithdraw____")
addrWithTranDep := sdk.AccAddress("addrWithTranDep_____")
Expand Down Expand Up @@ -97,6 +98,7 @@ func TestSendRestrictionFn(t *testing.T) {
if markerType == restricted {
rv.AccessControl = []types.AccessGrant{
{Address: addrWithTransfer.String(), Permissions: types.AccessList{types.Access_Transfer}},
{Address: addrWithForceTransfer.String(), Permissions: types.AccessList{types.Access_ForceTransfer}},
{Address: addrWithDeposit.String(), Permissions: types.AccessList{types.Access_Deposit}},
{Address: addrWithWithdraw.String(), Permissions: types.AccessList{types.Access_Withdraw}},
{Address: addrWithTranDep.String(), Permissions: types.AccessList{types.Access_Deposit, types.Access_Transfer}},
Expand Down Expand Up @@ -196,6 +198,13 @@ func TestSendRestrictionFn(t *testing.T) {
amt: cz(c(1, rDenomNoAttr)),
expErr: "",
},
{
name: "addr has force transfer, denom without attrs",
from: addrWithForceTransfer,
to: addrWithoutAttrs,
amt: cz(c(1, rDenomNoAttr)),
expErr: fmt.Sprintf("%s does not have transfer permissions for %s", addrWithForceTransfer.String(), rDenomNoAttr),
},
{
name: "addr has transfer, denom with 3 attrs, to has none",
from: addrWithTransfer,
Expand Down
5 changes: 3 additions & 2 deletions x/marker/types/marker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,15 @@ func TestHasAccess(t *testing.T) {
Address: addrAll.String(),
Permissions: []Access{
Access_Mint, Access_Burn, Access_Deposit, Access_Withdraw,
Access_Delete, Access_Admin, Access_Transfer,
Access_Delete, Access_Admin, Access_Transfer, Access_ForceTransfer,
},
},
{Address: addrDup.String(), Permissions: []Access{Access_Admin}},
{
Address: addrAllButWithdraw.String(),
Permissions: []Access{
Access_Mint, Access_Burn, Access_Deposit,
Access_Delete, Access_Admin, Access_Transfer,
Access_Delete, Access_Admin, Access_Transfer, Access_ForceTransfer,
},
},
{Address: addrOnlyTransfer.String(), Permissions: []Access{Access_Transfer}},
Expand Down Expand Up @@ -531,6 +531,7 @@ func TestHasAccess(t *testing.T) {
{name: "address has all: delete", addr: addrAll, role: Access_Delete, expHas: true},
{name: "address has all: admin", addr: addrAll, role: Access_Admin, expHas: true},
{name: "address has all: transfer", addr: addrAll, role: Access_Transfer, expHas: true},
{name: "address has all: force transfer", addr: addrAll, role: Access_ForceTransfer, expHas: true},
}

for _, tc := range tests {
Expand Down

0 comments on commit f31acf8

Please sign in to comment.