(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestKeystoreImportWithOpts(t *testing.T) { |
| 11 | password := []byte("password") |
| 12 | // pre-create a new private key |
| 13 | private, err := NewBLS12381PrivateKey() |
| 14 | require.NoError(t, err) |
| 15 | // get the address |
| 16 | address := private.PublicKey().Address().Bytes() |
| 17 | // encrypt the private key |
| 18 | encrypted, err := EncryptPrivateKey(private.PublicKey().Bytes(), private.Bytes(), password, private.PublicKey().Address().String()) |
| 19 | require.NoError(t, err) |
| 20 | // create a new in-memory keystore |
| 21 | ks := NewKeystoreInMemory() |
| 22 | // execute the function call |
| 23 | require.NoError(t, ks.Import(encrypted, ImportOpts{ |
| 24 | Address: address, |
| 25 | Nickname: "pablito", |
| 26 | })) |
| 27 | // check the key was imported |
| 28 | got, err := ks.GetKey(address, string(password)) |
| 29 | require.NoError(t, err) |
| 30 | // validate got vs expected |
| 31 | require.EqualExportedValues(t, private, got) |
| 32 | // check the key was imported by nickname |
| 33 | pKey, err := ks.GetKeyGroup(string(password), GetKeyGroupOpts{ |
| 34 | Nickname: "pablito", |
| 35 | }) |
| 36 | require.NoError(t, err) |
| 37 | // validate got vs expected |
| 38 | require.EqualExportedValues(t, private, pKey.PrivateKey) |
| 39 | } |
| 40 | |
| 41 | func TestKeystoreImportRawWithOpts(t *testing.T) { |
| 42 | password := "password" |
nothing calls this directly
no test coverage detected