Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed May 13, 2024
1 parent a29d9c0 commit 27a0727
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions client/internal/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func init() {
_ = clearFile.Close()
}

// LoadContract loads the AlgoDID smart contract ABI from JSON file.
func LoadContract() *abi.Contract {
abiFile, _ := StorageContracts.Open("AlgoDID.abi.json")
abiContents, _ := io.ReadAll(abiFile)
Expand Down
46 changes: 30 additions & 16 deletions client/ui/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,45 @@ func getKmdClient() (kmd.Client, error) {
func getSandboxAccounts() ([]crypto.Account, error) {
client, err := getKmdClient()
if err != nil {
return nil, fmt.Errorf("Failed to create kmd client: %+v", err)
return nil, fmt.Errorf("Failed to create kmd client: %w", err)
}

resp, err := client.ListWallets()
if err != nil {
return nil, fmt.Errorf("Failed to list wallets: %+v", err)
return nil, fmt.Errorf("Failed to list wallets: %w", err)
}

var walletId string
var walletID string
for _, wallet := range resp.Wallets {
if wallet.Name == "unencrypted-default-wallet" {
walletId = wallet.ID
walletID = wallet.ID
}
}

if walletId == "" {
if walletID == "" {
return nil, fmt.Errorf("No wallet named %s", "unencrypted-default-wallet")
}

whResp, err := client.InitWalletHandle(walletId, "")
whResp, err := client.InitWalletHandle(walletID, "")
if err != nil {
return nil, fmt.Errorf("Failed to init wallet handle: %+v", err)
return nil, fmt.Errorf("Failed to init wallet handle: %w", err)
}

addrResp, err := client.ListKeys(whResp.WalletHandleToken)
if err != nil {
return nil, fmt.Errorf("Failed to list keys: %+v", err)
return nil, fmt.Errorf("Failed to list keys: %w", err)
}

var accts []crypto.Account
accts := make([]crypto.Account, len(addrResp.Addresses))
for _, addr := range addrResp.Addresses {
expResp, err := client.ExportKey(whResp.WalletHandleToken, "", addr)
if err != nil {
return nil, fmt.Errorf("Failed to export key: %+v", err)
return nil, fmt.Errorf("Failed to export key: %w", err)
}

acct, err := crypto.AccountFromPrivateKey(expResp.PrivateKey)
if err != nil {
return nil, fmt.Errorf("Failed to create account from private key: %+v", err)
return nil, fmt.Errorf("Failed to create account from private key: %w", err)
}

accts = append(accts, acct)
Expand All @@ -96,6 +96,7 @@ func req(t *testing.T, method string, endpoint string, reqBody string) *http.Res
require.NoError(t, err)

res, err := http.DefaultClient.Do(req)
require.NoError(t, err)

return res
}
Expand All @@ -117,6 +118,9 @@ func TestMain(m *testing.M) {
}

status, err := algodClient.Status().Do(context.Background())
if err != nil {
panic(err)
}

// type NetworkProfile struct {
// // Profile name.
Expand Down Expand Up @@ -158,6 +162,9 @@ func TestMain(m *testing.M) {
}

srv, err := LocalAPIServer(localStore, cl, logger)
if err != nil {
panic(err)
}

logger.Debug("starting local API server on localhost:9090")
go func() {
Expand All @@ -169,12 +176,14 @@ func TestMain(m *testing.M) {

func TestReady(t *testing.T) {
res := req(t, http.MethodGet, "ready", "")
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)
}

func TestList(t *testing.T) {
res := req(t, http.MethodGet, "list", "")
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)

Expand All @@ -186,16 +195,19 @@ func TestList(t *testing.T) {

func TestRegister(t *testing.T) {
res := req(t, http.MethodPost, "register", `{"name": "TestRegister", "recovery_key": "test", "network": "custom"}`)
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)
}

func TestListAfterRegister(t *testing.T) {
res := req(t, http.MethodPost, "register", `{"name": "TestListAfterRegister", "recovery_key": "test", "network": "custom"}`)
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)

res = req(t, http.MethodGet, "list", "")
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)

Expand All @@ -207,6 +219,7 @@ func TestListAfterRegister(t *testing.T) {

func TestUpdate(t *testing.T) {
res := req(t, http.MethodPost, "register", `{"name": "TestUpdate", "recovery_key": "test", "network": "custom"}`)
defer res.Body.Close()

require.Equal(t, http.StatusOK, res.StatusCode)

Expand Down Expand Up @@ -249,25 +262,26 @@ func TestUpdate(t *testing.T) {

// Create the app

createdAppId, err := internal.CreateApp(algodClient, internal.LoadContract(), acct.Address, signer)
createdAppID, err := internal.CreateApp(algodClient, internal.LoadContract(), acct.Address, signer)
require.NoError(t, err)
require.Equal(t, uint64(profile.AppID), createdAppId)
fmt.Printf("Created app ID: %d\n", createdAppId)
require.Equal(t, uint64(profile.AppID), createdAppID)
fmt.Printf("Created app ID: %d\n", createdAppID)

appInfo, err := algodClient.GetApplicationByID(createdAppId).Do(context.Background())
appInfo, err := algodClient.GetApplicationByID(createdAppID).Do(context.Background())
require.NoError(t, err)
require.False(t, appInfo.Deleted)

// Sync with the network

res = req(t, http.MethodPost, "update", `{"name": "TestUpdate", "passphrase": "test"}`)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)

did, err := localStore.Get("TestUpdate")
require.NoError(t, err)

resolvedDid, err := internal.ResolveDID(createdAppId, acct.PublicKey, algodClient, "custom")
resolvedDid, err := internal.ResolveDID(createdAppID, acct.PublicKey, algodClient, "custom")
require.NoError(t, err)

fmt.Println(string(resolvedDid))
Expand Down
2 changes: 1 addition & 1 deletion client/ui/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (p *Provider) registerHandlerFunc(w http.ResponseWriter, r *http.Request) {
}
if err = p.Register(network, name, passphrase); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
w.Write([]byte(err.Error())) //nolint:errcheck,gosec
return
}
_, _ = w.Write([]byte("ok"))
Expand Down

0 comments on commit 27a0727

Please sign in to comment.