public async Task CanUpdateMultiplePropertiesInOneCall() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newExpiration = Generator.TruncatedFutureDate(2400, 4800); var newEndorsement = new Endorsement(newPublicKey); var newRenewal = TimeSpan.FromDays(Generator.Integer(60, 90)); var updatedPayer = _network.PayerWithKeys(newPrivateKey); var newMemo = Generator.Code(50); fx.Client.Configure(ctx => ctx.Payer = updatedPayer); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration, Administrator = newEndorsement, RenewPeriod = newRenewal, Memo = newMemo }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); //Assert.Equal(newExpiration, info.Expiration); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(newRenewal, info.RenewPeriod); Assert.Equal(newMemo, info.Memo); }
public async Task CanRetriveAClaimAsync() { await using var accountFx = await TestAccount.CreateAsync(_network); var(publicKey1, privateKey1) = Generator.KeyPair(); var(publicKey2, privateKey2) = Generator.KeyPair(); var claim = new Claim { Address = accountFx.Record.Address, Hash = new SHA384Managed().ComputeHash(Generator.KeyPair().publicKey.ToArray()), Endorsements = new Endorsement[] { publicKey1, publicKey2 }, ClaimDuration = TimeSpan.FromDays(Generator.Integer(100, 200)) }; accountFx.Client.Configure(ctx => { ctx.Payer = _network.PayerWithKeys(privateKey1, privateKey2); }); var receipt = await accountFx.Client.AddClaimAsync(claim); Assert.Equal(ResponseCode.Success, receipt.Status); for (int tryNo = 0; tryNo < 20; tryNo++) { try { var copy = await accountFx.Client.GetClaimAsync(claim.Address, claim.Hash); Assert.NotNull(copy); // We cannot do this because of a // network bug //Assert.Equal(claim, copy); // instead we must do this: Assert.Equal(claim.Address, copy.Address); Assert.Equal(claim.Hash.ToArray(), copy.Hash.ToArray()); Assert.Equal(new Endorsement(claim.Endorsements), copy.Endorsements[0]); // Note: this is a bug in the network. Assert.Equal(claim.ClaimDuration, copy.ClaimDuration); if (tryNo > 0) { _network.Output?.WriteLine($"NETWORK SUCCESS: Finally Worked, was able to get the claim after {tryNo} retries."); } return; } catch (PrecheckException pex) when(pex.Status == ResponseCode.ClaimNotFound) { _network.Output?.WriteLine($"NETWORK ERROR: Ran across intermitent Get Claim Race Condition in Network, Retry:{tryNo}"); _network.Output?.WriteLine(pex.StackTrace); } } _network.Output?.WriteLine("NETWORK ERROR: Gave Up, network won't let us finish this test."); }
public async Task DeleteContractWithoutAdminKeyRaisesError() { var(publicKey, privateKey) = Generator.KeyPair(); await using var fx = await GreetingContract.SetupAsync(_network); fx.ContractParams.Administrator = publicKey; // Default is to use Payor's fx.Client.Configure(ctx => ctx.Payer = _network.PayerWithKeys(privateKey)); await fx.CompleteCreateAsync(); await using (var client = _network.NewClient()) // Will not have private key { var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await client.DeleteContractAsync(fx.ContractRecord.Contract, _network.Payer); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); Assert.StartsWith("Unable to delete contract, status: InvalidSignature", tex.Message); } }
public async Task CanCreateAClaimAsync() { await using var test = await TestAccount.CreateAsync(_network); var(publicKey1, privateKey1) = Generator.KeyPair(); var(publicKey2, privateKey2) = Generator.KeyPair(); var claim = new Claim { Address = test.Record.Address, Hash = Generator.SHA384Hash(), Endorsements = new Endorsement[] { publicKey1, publicKey2 }, ClaimDuration = TimeSpan.FromDays(Generator.Integer(10, 20)) }; var receipt = await test.Client.AddClaimAsync(claim, ctx => { ctx.Payer = _network.PayerWithKeys(privateKey1, privateKey2); }); Assert.Equal(ResponseCode.Success, receipt.Status); }