Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions common/query/accountDatasetQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}
Expand Down
9 changes: 5 additions & 4 deletions common/query/accountDatasetQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestAccountDatasetsQuery_GetAccountDatasetEscrowApproval(t *testing.T) {
TableName string
}
type args struct {
recipientAccountAddress string
accountAddress string
}
tests := []struct {
name string
Expand All @@ -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,
Expand All @@ -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
Expand Down