public void TestPeerInfoMarshal() { var a = MustAddr("/ip4/1.2.3.4/tcp/4536"); var b = MustAddr("/ip4/1.2.3.8/udp/7777"); var id = PeerId.Decode("QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"); var pi = new PeerInfo(id, new[] { a, b }); var data = pi.MarshalJson(); var pi2 = PeerInfo.UnmarshalJson(data); Assert.That(pi2.Id, Is.EqualTo(pi.Id)); Assert.That(pi2.Addresses[0], Is.EqualTo(pi.Addresses[0])); Assert.That(pi2.Addresses[1], Is.EqualTo(pi.Addresses[1])); Assert.That(pi2.Id.ToString(), Is.EqualTo(id.ToString())); }
public void TestIdMatchesPrivateKey() { Action <KeySet> test = (ks) => { var p1 = PeerId.Decode(ks.hpkp); Assert.Equal(p1.ToString(Multibase.Base16), ks.hpk); Assert.True(p1.MatchesPrivateKey(ks.sk)); var p2 = new PeerId(ks.sk); Assert.Equal(p1, p2); }; test(gen1); test(gen2); test(man); }
public void TestIdMatchesPublicKey() { Action <KeySet> test = (ks) => { var p1 = PeerId.Decode(ks.hpkp); Assert.That(p1.ToString(Multibase.Base16), Is.EqualTo(ks.hpk)); Assert.That(p1.MatchesPublicKey(ks.pk), Is.True); var p2 = new PeerId(ks.pk); Assert.That(p1, Is.EqualTo(p2)); Assert.That(p2.ToString(Multibase.Base58), Is.EqualTo(ks.hpkp)); }; test(gen1); test(gen2); test(man); }
private static PeerId Id(string s) => PeerId.Decode(s);