diff --git a/common/query/accountDatasetQuery.go b/common/query/accountDatasetQuery.go index 0f9805a4e..9fdbcbab2 100644 --- a/common/query/accountDatasetQuery.go +++ b/common/query/accountDatasetQuery.go @@ -20,9 +20,7 @@ type ( GetLatestAccountDataset(setterAccountAddress, recipientAccountAddress, property string) (str string, args []interface{}) InsertAccountDataset(dataset *model.AccountDataset) (str string, args []interface{}) RemoveAccountDataset(dataset *model.AccountDataset) [][]interface{} - GetAccountDatasetEscrowApproval( - recipientAccountAddress string, - ) (qStr string, args []interface{}) + GetAccountDatasetEscrowApproval(accountAddress string) (qStr string, args []interface{}) ExtractModel(dataset *model.AccountDataset) []interface{} BuildModel(datasets []*model.AccountDataset, rows *sql.Rows) ([]*model.AccountDataset, error) Scan(dataset *model.AccountDataset, row *sql.Row) error @@ -107,16 +105,16 @@ func (adq *AccountDatasetQuery) RemoveAccountDataset(dataset *model.AccountDatas } // GetAccountDatasetEscrowApproval represents query for get account dataset for AccountDatasetEscrowApproval property -func (adq *AccountDatasetQuery) GetAccountDatasetEscrowApproval( - recipientAccountAddress string, -) (qStr string, args []interface{}) { +// SetterAccountAddress and RecipientAccountAddress must be the same person +func (adq *AccountDatasetQuery) GetAccountDatasetEscrowApproval(accountAddress string) (qStr string, args []interface{}) { return fmt.Sprintf( - "SELECT %s FROM %s WHERE recipient_account_address = ? AND property = ? AND latest = ?", + "SELECT %s FROM %s WHERE setter_account_address = ? AND recipient_account_address = ? AND property = ? AND latest = ?", strings.Join(adq.Fields, ", "), adq.getTableName(), ), []interface{}{ - recipientAccountAddress, - "AccountDatasetEscrowApproval", + accountAddress, + accountAddress, + model.AccountDatasetProperty_AccountDatasetEscrowApproval.String(), 1, } } diff --git a/common/query/accountDatasetQuery_test.go b/common/query/accountDatasetQuery_test.go index 792a07266..8f5fe93ce 100644 --- a/common/query/accountDatasetQuery_test.go +++ b/common/query/accountDatasetQuery_test.go @@ -196,7 +196,7 @@ func TestAccountDatasetsQuery_GetAccountDatasetEscrowApproval(t *testing.T) { TableName string } type args struct { - recipientAccountAddress string + accountAddress string } tests := []struct { name string @@ -208,10 +208,11 @@ func TestAccountDatasetsQuery_GetAccountDatasetEscrowApproval(t *testing.T) { { name: "wantSuccess", fields: fields(*mockDatasetQuery), - args: args{recipientAccountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"}, + args: args{accountAddress: "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN"}, wantQStr: "SELECT setter_account_address, recipient_account_address, property, value, is_active, latest, height FROM account_dataset " + - "WHERE recipient_account_address = ? AND property = ? AND latest = ?", + "WHERE setter_account_address = ? AND recipient_account_address = ? AND property = ? AND latest = ?", wantArgs: []interface{}{ + "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN", "AccountDatasetEscrowApproval", 1, @@ -224,7 +225,7 @@ func TestAccountDatasetsQuery_GetAccountDatasetEscrowApproval(t *testing.T) { Fields: tt.fields.Fields, TableName: tt.fields.TableName, } - gotQStr, gotArgs := adq.GetAccountDatasetEscrowApproval(tt.args.recipientAccountAddress) + gotQStr, gotArgs := adq.GetAccountDatasetEscrowApproval(tt.args.accountAddress) if gotQStr != tt.wantQStr { t.Errorf("GetAccountDatasetEscrowApproval() gotQStr = \n%v, want \n%v", gotQStr, tt.wantQStr) return