예제 #1
0
        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()));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 private static PeerId Id(string s) => PeerId.Decode(s);