public void TestObjectPut() { var rand = new Random(); var payload = new byte[1024]; rand.NextBytes(payload); var obj = new FSObject { Header = new Header { OwnerId = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), ContainerId = cid, }, Payload = ByteString.CopyFrom(payload), }; using var client = new Client.Client(key, host); using var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(10)); var session = client.CreateSession(20).Result; var o = client.PutObject(obj, new CallOptions { Ttl = 1, Session = session }, source.Token).Result; Console.WriteLine(o.String()); Assert.AreNotEqual("", o.String()); }
public void TestObjectPut() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var cid = ContainerID.FromBase58String("RuzuV3RDstuVtWoDzsTsuNFiakaaGGN24EbNSUFGaiQ"); var payload = Encoding.ASCII.GetBytes("hello"); var obj = new V2Object { Header = new Header { OwnerId = key.ToOwnerID(), ContainerId = cid, }, Payload = ByteString.CopyFrom(payload), }; var client = new Client.Client(key, host); var source1 = new CancellationTokenSource(); source1.CancelAfter(TimeSpan.FromMinutes(1)); var session = client.CreateSession(source1.Token, ulong.MaxValue); source1.Cancel(); var source2 = new CancellationTokenSource(); source2.CancelAfter(TimeSpan.FromMinutes(1)); var o = client.PutObject(source2.Token, new PutObjectParams { Object = obj }, new CallOptions { Ttl = 2, Session = session }).Result; Console.WriteLine(o.ToBase58String()); Assert.AreNotEqual("", o.ToBase58String()); }
public void TestObjectPutFull() { var obj = RandomFullObject(1024); Console.WriteLine("created object, id=" + obj.ObjectId.String()); using var client = new Client.Client(key, host); using var source = new CancellationTokenSource(); var o = client.PutObject(obj, new CallOptions { Ttl = 2 }, source.Token).Result; Console.WriteLine("get object, id=" + o.String()); Assert.AreNotEqual("", o.String()); }
public void TestObjectPutStream() { string path = "objectputstream.data"; var rand = new Random(); var payload = new byte[1024]; rand.NextBytes(payload); var file = File.Create(path); file.Write(payload, 0, 1024); file.Flush(); file.Seek(0, SeekOrigin.Begin); var obj = new FSObject { Header = new Header { OwnerId = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), ContainerId = cid, }, }; obj.Attributes.Add(new Header.Types.Attribute { Key = "category", Value = "test" }); using var client = new Client.Client(key, host); using var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(10)); var session = client.CreateSession(20).Result; var o = client.PutObject(obj.Header, file, new CallOptions { Ttl = 1, Session = session }, source.Token).Result; Console.WriteLine(o.String()); Assert.AreNotEqual("", o.String()); File.Delete(path); }
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()); }