Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: update by coderabbit #73

Merged
merged 16 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update UnlockAccountHelper
  • Loading branch information
peaceandwhisky committed Nov 7, 2024
commit 81d374986686c8766eee1e049a942b7c38e60538
15 changes: 12 additions & 3 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ func TestDeleteAccountE2E(t *testing.T) {
}

// Step 2: Unlock the account
testutil.UnlockAccountHelper(t, taStoreContract, accountId, tc.creator)
err = testutil.UnlockAccountHelper(t, taStoreContract, accountId, tc.creator)
if err != nil {
t.Fatalf("Failed to unlock account: %v", err)
}

// Step 3: Delete the account
deleteSig, err := testutil.NewPbTimedSignature(taStoreContract, tc.sender, uint64(tc.validFor), common.HexToHash(impl.DELETE_ACCOUNT_FUNCTION_HASH))
Expand Down Expand Up @@ -516,7 +519,10 @@ func TestSignE2E(t *testing.T) {
}

// Step 2: Unlock the account
testutil.UnlockAccountHelper(t, taStoreContract, accountId, tc.creator)
err = testutil.UnlockAccountHelper(t, taStoreContract, accountId, tc.creator)
if err != nil {
t.Fatalf("Failed to unlock account: %v", err)
}

// Step 3: Sign the message
signSig, err := testutil.NewPbTimedSignature(taStoreContract, tc.sender, uint64(tc.validFor), common.HexToHash(impl.SIGN_FUNCTION_HASH))
Expand Down Expand Up @@ -741,7 +747,10 @@ func TestIsAccountLockedE2E(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create account: %v", err)
}
testutil.UnlockAccountHelper(t, taStoreContract, accountId, alicePrivKey)
err = testutil.UnlockAccountHelper(t, taStoreContract, accountId, alicePrivKey)
if err != nil {
t.Fatalf("Failed to unlock account: %v", err)
}
return accountId
},
expectLocked: false,
Expand Down
11 changes: 9 additions & 2 deletions test/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func ApproveAddressHelper(t *testing.T, taStoreContract *framework.Contract, acc
}

// Helper function to unlock an account
func UnlockAccountHelper(t *testing.T, taStoreContract *framework.Contract, accountId string, ownerPrivKey *ecdsa.PrivateKey) {
func UnlockAccountHelper(t *testing.T, taStoreContract *framework.Contract, accountId string, ownerPrivKey *ecdsa.PrivateKey) error {
validFor := uint64(time.Now().AddDate(1, 0, 0).Unix())
unlockSig, err := NewPbTimedSignature(taStoreContract, ownerPrivKey, validFor, common.HexToHash(impl.UNLOCK_ACCOUNT_FUNCTION_HASH))
if err != nil {
t.Fatalf("Failed to generate timed signature: %v", err)
return fmt.Errorf("failed to generate timed signature: %w", err)
}
unlockAccountRequest := &pb.UnlockAccountRequest{
Base: &pb.AccountOperationRequest{
Expand All @@ -64,6 +64,13 @@ func UnlockAccountHelper(t *testing.T, taStoreContract *framework.Contract, acco
},
}
_, resp, err := UnlockAccount(unlockAccountRequest)
if err != nil {
return fmt.Errorf("failed to unlock account: %w", err)
}
if resp.StatusCode != 200 {
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
assert.NoError(t, err, "Failed to unlock account")
assert.Equal(t, 200, resp.StatusCode)
return nil
}