fix_: return array of account without accounts key (#5576)

This commit is contained in:
Godfrain Jacques 2024-07-25 06:10:13 -07:00 committed by GitHub
parent 2bbdb35f6c
commit 5e88d5b498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 21 deletions

View File

@ -13,15 +13,9 @@ type AccountsCommand struct {
Db *sql.DB
}
type AccountsResponse struct {
Accounts []types.Address `json:"accounts"`
}
func (c *AccountsCommand) dAppToAccountsResponse(dApp *persistence.DApp) (string, error) {
response := AccountsResponse{
Accounts: []types.Address{dApp.SharedAccount},
}
responseJSON, err := json.Marshal(response)
addresses := []types.Address{dApp.SharedAccount}
responseJSON, err := json.Marshal(addresses)
if err != nil {
return "", fmt.Errorf("failed to marshal response: %v", err)
}

View File

@ -55,10 +55,11 @@ func TestGetAccountForPermittedDApp(t *testing.T) {
response, err := cmd.Execute(request)
assert.NoError(t, err)
result := &AccountsResponse{}
err = json.Unmarshal([]byte(response), result)
// Unmarshal the response into a slice of addresses
var result []types.Address
err = json.Unmarshal([]byte(response), &result)
assert.NoError(t, err)
assert.Len(t, result.Accounts, 1)
assert.Equal(t, sharedAccount, result.Accounts[0])
assert.Len(t, result, 1)
assert.Equal(t, sharedAccount, result[0])
}

View File

@ -89,12 +89,13 @@ func TestRequestAccountsAcceptedAndRequestAgain(t *testing.T) {
response, err := cmd.Execute(request)
assert.NoError(t, err)
result := &AccountsResponse{}
err = json.Unmarshal([]byte(response), result)
// Unmarshal the response into a slice of addresses
var result []types.Address
err = json.Unmarshal([]byte(response), &result)
assert.NoError(t, err)
assert.Len(t, result.Accounts, 1)
assert.Equal(t, accountAddress, result.Accounts[0])
assert.Len(t, result, 1)
assert.Equal(t, accountAddress, result[0])
// Check dApp in the database
dApp, err := persistence.SelectDAppByUrl(db, request.URL)
@ -108,11 +109,11 @@ func TestRequestAccountsAcceptedAndRequestAgain(t *testing.T) {
response, err = cmd.Execute(request)
assert.NoError(t, err)
err = json.Unmarshal([]byte(response), result)
err = json.Unmarshal([]byte(response), &result)
assert.NoError(t, err)
assert.Len(t, result.Accounts, 1)
assert.Equal(t, accountAddress, result.Accounts[0])
assert.Len(t, result, 1)
assert.Equal(t, accountAddress, result[0])
}
func TestRequestAccountsRejected(t *testing.T) {

View File

@ -77,7 +77,7 @@ func TestRequestAccountsSwitchChainAndSendTransactionFlow(t *testing.T) {
// Request accounts, now for real
request = "{\"method\": \"eth_requestAccounts\", \"params\": [], \"url\": \"http://testDAppURL123\", \"name\": \"testDAppName\", \"iconUrl\": \"http://testDAppIconUrl\" }"
expectedResponse := strings.ToLower(fmt.Sprintf(`{"accounts":["%s"]}`, accountAddress.Hex()))
expectedResponse := strings.ToLower(fmt.Sprintf(`["%s"]`, accountAddress.Hex()))
response, err = api.CallRPC(request)
assert.NoError(t, err)
assert.Equal(t, expectedResponse, response)
@ -98,7 +98,7 @@ func TestRequestAccountsSwitchChainAndSendTransactionFlow(t *testing.T) {
// Check the account after switching chain
request = "{\"method\": \"eth_accounts\", \"params\": [], \"url\": \"http://testDAppURL123\", \"name\": \"testDAppName\", \"iconUrl\": \"http://testDAppIconUrl\" }"
expectedResponse = strings.ToLower(fmt.Sprintf(`{"accounts":["%s"]}`, accountAddress.Hex()))
expectedResponse = strings.ToLower(fmt.Sprintf(`["%s"]`, accountAddress.Hex()))
response, err = api.CallRPC(request)
assert.NoError(t, err)
assert.Equal(t, expectedResponse, response)