Esempio n. 1
0
        public void TestEpoch()
        {
            using var client = new Client.Client(key, host);
            using var source = new CancellationTokenSource();
            source.CancelAfter(TimeSpan.FromMinutes(1));
            var epoch = client.Epoch(context: source.Token).Result;

            Console.WriteLine(epoch);
            Assert.IsTrue(0 < epoch);
        }
Esempio n. 2
0
        public void TestEpoch()
        {
            var host   = "localhost:8080";
            var key    = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif();
            var client = new Client.Client(key, host);
            var source = new CancellationTokenSource();

            source.CancelAfter(TimeSpan.FromMinutes(1));
            var epoch = client.Epoch(source.Token);

            Console.WriteLine(epoch);
        }
Esempio n. 3
0
        public void TestObjectPutStorageGroup()
        {
            List <ObjectID> oids = new() { ObjectID.FromString("7Q7fPKESmRJ1VGHKcB2pB4JWVebsQzrJypwQiNLU1ekv"), ObjectID.FromString("HwfVt5i9ucjPUhRpHyxamnfTvhKtTUysCZWXcJ6YZsZ4") };

            using var client = new Client.Client(key, host);
            byte[] tzh  = null;
            ulong  size = 0;

            foreach (var oid in oids)
            {
                var address = new Address(cid, oid);
                using var source = new CancellationTokenSource();
                source.CancelAfter(TimeSpan.FromMinutes(1));
                var oo = client.GetObjectHeader(address, false, false, new CallOptions {
                    Ttl = 2
                }, source.Token).Result;
                if (tzh is null)
                {
                    tzh = oo.PayloadHomomorphicHash.Sum.ToByteArray();
                }
                else
                {
                    tzh = TzHash.Concat(new() { tzh, oo.PayloadHomomorphicHash.Sum.ToByteArray() });
                }
                size += oo.PayloadSize;
            }
            var epoch = client.Epoch().Result;

            StorageGroup.StorageGroup sg = new()
            {
                ValidationDataSize = size,
                ValidationHash     = new()
                {
                    Type = ChecksumType.Tz,
                    Sum  = ByteString.CopyFrom(tzh)
                },
                ExpirationEpoch = epoch + 100,
            };
            sg.Members.AddRange(oids);
            var obj = new FSObject
            {
                Header = new Header
                {
                    OwnerId     = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()),
                    ContainerId = cid,
                    ObjectType  = ObjectType.StorageGroup,
                },
                Payload = ByteString.CopyFrom(sg.ToByteArray()),
            };

            using var source1 = new CancellationTokenSource();
            source1.CancelAfter(TimeSpan.FromMinutes(1));
            var session = client.CreateSession(ulong.MaxValue, context: source1.Token).Result;

            source1.Cancel();
            using var source2 = new CancellationTokenSource();
            source2.CancelAfter(TimeSpan.FromMinutes(1));
            var o = client.PutObject(obj, new CallOptions {
                Ttl = 2, Session = session
            }, source2.Token).Result;

            Console.WriteLine(o.String());
            Assert.AreNotEqual("", o.String());
        }