(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestLocalKeyStore(t *testing.T) { |
| 31 | Convey("set and get key", t, func() { |
| 32 | initLocalKeyStore() |
| 33 | So(localKey, ShouldNotBeNil) |
| 34 | gotPrivate, err := GetLocalPrivateKey() |
| 35 | So(gotPrivate, ShouldBeNil) |
| 36 | So(err, ShouldEqual, ErrNilField) |
| 37 | gotPublic, err := GetLocalPublicKey() |
| 38 | So(gotPublic, ShouldBeNil) |
| 39 | So(err, ShouldEqual, ErrNilField) |
| 40 | |
| 41 | privKey1, pubKey1, _ := asymmetric.GenSecp256k1KeyPair() |
| 42 | privKey2, pubKey2, _ := asymmetric.GenSecp256k1KeyPair() |
| 43 | SetLocalKeyPair(privKey1, pubKey1) |
| 44 | SetLocalKeyPair(privKey2, pubKey2) // no effect |
| 45 | gotPrivate, err = GetLocalPrivateKey() |
| 46 | So(err, ShouldBeNil) |
| 47 | gotPublic, err = GetLocalPublicKey() |
| 48 | So(err, ShouldBeNil) |
| 49 | So(bytes.Compare(gotPrivate.Serialize(), privKey1.Serialize()), ShouldBeZeroValue) |
| 50 | So(gotPublic.IsEqual(pubKey1), ShouldBeTrue) |
| 51 | So(gotPrivate.PubKey().IsEqual(pubKey1), ShouldBeTrue) |
| 52 | ResetLocalKeyStore() |
| 53 | }) |
| 54 | Convey("set and get key", t, func() { |
| 55 | initLocalKeyStore() |
| 56 | So(localKey, ShouldNotBeNil) |
| 57 | gotID, err := GetLocalNodeIDBytes() |
| 58 | So(gotID, ShouldBeNil) |
| 59 | So(err, ShouldEqual, ErrNilField) |
| 60 | gotNonce, err := GetLocalNonce() |
| 61 | So(gotNonce, ShouldBeNil) |
| 62 | So(err, ShouldEqual, ErrNilField) |
| 63 | SetLocalNodeIDNonce([]byte("aaa"), nil) |
| 64 | SetLocalNodeIDNonce([]byte("aaa"), &mine.Uint256{A: 1, B: 1, C: 1, D: 1}) |
| 65 | gotID, err = GetLocalNodeIDBytes() |
| 66 | So(bytes.Compare(gotID, []byte("aaa")), ShouldBeZeroValue) |
| 67 | So(err, ShouldBeNil) |
| 68 | gotNonce, err = GetLocalNonce() |
| 69 | So(*gotNonce == mine.Uint256{A: 1, B: 1, C: 1, D: 1}, ShouldBeTrue) |
| 70 | So(err, ShouldBeNil) |
| 71 | rawNodeID := &proto.RawNodeID{} |
| 72 | nodeIDBefore := rawNodeID.ToNodeID() |
| 73 | SetLocalNodeIDNonce(nodeIDBefore.ToRawNodeID().CloneBytes(), nil) |
| 74 | nodeID, err := GetLocalNodeID() |
| 75 | So(nodeID, ShouldResemble, nodeIDBefore) |
| 76 | }) |
| 77 | } |
nothing calls this directly
no test coverage detected