Skip to content

Commit

Permalink
Merge pull request #258 from ankur325/fix-approval-defect
Browse files Browse the repository at this point in the history
Defect Fix : Approvals were getting overwritten in store.
  • Loading branch information
ashcherbakov committed Feb 24, 2022
2 parents 3788286 + 9f117b9 commit a355226
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
11 changes: 11 additions & 0 deletions integration_tests/cli/auth-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ check_response "$result" "\"product_name\": \"$productName\""

test_divider

echo "Get $user account and confirm that alice and jack are set still present as approvers, also the sequence number should be 3 as we executed 3 txs"
result=$(dcld query auth account --address=$user_address)
check_response_and_report "$result" $user_address "json"
check_response_and_report "$result" $jack_address "json"
check_response_and_report "$result" $alice_address "json"
check_response_and_report "$result" '"info": "Alice is approving this account"' "json"
check_response_and_report "$result" '"info": "Jack is proposing this account"' "json"
check_response_and_report "$result" '"sequence": "3"' "json"

test_divider

echo "Alice proposes to revoke account for $user"
result=$(echo $passphrase | dcld tx auth propose-revoke-account --address="$user_address" --info="Alice proposes to revoke account" --from alice --yes)
check_response "$result" "\"code\": 0"
Expand Down
2 changes: 1 addition & 1 deletion x/dclauth/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account authtypes.AccountI) {
dclAcc.GetAddress(), dclAcc.GetPubKey(),
dclAcc.GetAccountNumber(), dclAcc.GetSequence(),
)
dclAccO := types.NewAccount(ba, dclAcc.GetRoles(), nil, dclAcc.GetVendorID())
dclAccO := types.NewAccount(ba, dclAcc.GetRoles(), dclAcc.GetApprovals(), dclAcc.GetVendorID())

k.SetAccountO(ctx, *dclAccO)
}
Expand Down
5 changes: 5 additions & 0 deletions x/dclauth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type DCLAccountI interface {

GetRoles() []AccountRole
GetVendorID() int32
GetApprovals() []*Grant
}

// NewAccount creates a new Account object.
Expand Down Expand Up @@ -99,6 +100,10 @@ func (acc Account) GetRoles() []AccountRole {
return acc.Roles
}

func (acc Account) GetApprovals() []*Grant {
return acc.Approvals
}

func (acc Account) GetVendorID() int32 {
return acc.VendorID
}
Expand Down
92 changes: 92 additions & 0 deletions x/dclauth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,95 @@ func TestPendingAccount_HasApprovalFrom(t *testing.T) {
})
}
}

func TestAccount_GetApprovals(t *testing.T) {
type fields struct {
BaseAccount *types.BaseAccount
Roles []AccountRole
Approvals []*Grant
VendorID int32
}
tests := []struct {
name string
fields fields
want []*Grant
}{
{
name: `account having 2 approvals`,
fields: fields{
BaseAccount: &types.BaseAccount{},
Roles: []AccountRole{Vendor},
Approvals: []*Grant{
{
Address: "address1",
Info: "info1",
Time: 123,
},
{
Address: "address2",
Info: "",
Time: 456,
},
},
VendorID: 1,
},
want: []*Grant{
{
Address: "address1",
Info: "info1",
Time: 123,
},
{
Address: "address2",
Info: "",
Time: 456,
},
},
},
{
name: `account having 1 approval`,
fields: fields{
BaseAccount: &types.BaseAccount{},
Roles: []AccountRole{Vendor},
Approvals: []*Grant{
{
Address: "address1",
Info: "info1",
Time: 123,
},
},
VendorID: 1,
},
want: []*Grant{
{
Address: "address1",
Info: "info1",
Time: 123,
},
},
},
{
name: `account having 0 approvals`,
fields: fields{
BaseAccount: &types.BaseAccount{},
Roles: []AccountRole{Vendor},
VendorID: 1,
Approvals: []*Grant{},
},
want: []*Grant{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
acc := Account{
BaseAccount: tt.fields.BaseAccount,
Roles: tt.fields.Roles,
Approvals: tt.fields.Approvals,
VendorID: tt.fields.VendorID,
}
if got := acc.GetApprovals(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Account.GetApprovals() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit a355226

Please sign in to comment.