You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
package account
import (
"crypto/ecdsa""crypto/elliptic""crypto/rand""crypto/x509""encoding/pem""io/ioutil""os""testing""github.com/stretchr/testify/assert"
)
funcTestAccount(t*testing.T) {
// Create a temporary directory for the wallettempDir, err:=ioutil.TempDir("", "wallet")
assert.NoError(t, err)
deferos.RemoveAll(tempDir)
// Create a new local walletwallet, err:=NewLocalWallet(tempDir)
assert.NoError(t, err)
// Generate a new accountprivateKey, err:=ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
assert.NoError(t, err)
publicKey:=privateKey.PublicKeyaccount:=&Account{
Address: "testaccount",
PrivateKey: x509.MarshalECPrivateKey(privateKey),
signer: *privateKey,
}
// Store the account in the walleterr=wallet.StoreAccount(account)
assert.NoError(t, err)
// Retrieve the account from the walletloadedAccount, err:=wallet.GetAccount("testaccount")
assert.NoError(t, err)
assert.Equal(t, account.Address, loadedAccount.Address)
assert.Equal(t, account.PrivateKey, loadedAccount.PrivateKey)
assert.Equal(t, account.signer, loadedAccount.signer)
// Verify the stored account filefilePath:=tempDir+"/testaccount"assert.FileExists(t, filePath)
fileBytes, err:=ioutil.ReadFile(filePath)
assert.NoError(t, err)
assert.Equal(t, string(fileBytes), `{"address":"testaccount","privKey":"`+string(account.PrivateKey)+`"}`)
// List the accounts in the walletaccounts, err:=wallet.ListAccounts()
assert.NoError(t, err)
assert.Equal(t, []string{"testaccount"}, accounts)
// Delete the account from the walleterr=wallet.DeleteAccounts("testaccount")
assert.NoError(t, err)
assert.NoFileExists(t, filePath)
}
I'm sorry, but something went wrong. Here's the error message:
invalid_argument: protocol error: incomplete envelope: context deadline exceeded (Client.Timeout or context cancellation while reading body)
We're working hard to improve the quality of your experience. Please try again later. If the issue persists, our team is > available on [Discord](https://discord.gg/3XFf78nAx5).
定义测试用例
描述: 测试类型转换
特点:
结果:
描述: 测试LocalWallet功能
特点:
结果(chatgpt)
查看详细单测代码