예제 #1
0
        public void CanCreateContractType()
        {
            var contract = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000));
            var bytes    = Abi.EncodeAddressPart(contract);

            var endorsement = new Endorsement(KeyType.Contract, bytes);

            Assert.Equal(KeyType.Contract, endorsement.Type);
            Assert.Empty(endorsement.List);
            Assert.Equal(0U, endorsement.RequiredCount);
            Assert.Equal(bytes.ToArray(), endorsement.PublicKey.ToArray());
        }
예제 #2
0
 internal Endorsement ToEndorsement()
 {
     return(KeyCase switch
     {
         KeyOneofCase.Ed25519 => new Endorsement(KeyType.Ed25519, new ReadOnlyMemory <byte>(Ed25519Util.publicKeyPrefix.Concat(Ed25519.ToByteArray()).ToArray())),
         KeyOneofCase.RSA3072 => new Endorsement(KeyType.RSA3072, RSA3072.ToByteArray()),
         KeyOneofCase.ECDSA384 => new Endorsement(KeyType.ECDSA384, ECDSA384.ToByteArray()),
         KeyOneofCase.ContractID => new Endorsement(KeyType.Contract, Abi.EncodeAddressPart(ContractID.ToAddress())),
         KeyOneofCase.ThresholdKey => ThresholdKey.Keys.Keys.Count == 0 ? Endorsement.None : new Endorsement(ThresholdKey.Threshold, ThresholdKey.Keys.ToEndorsements()),
         KeyOneofCase.KeyList => KeyList.Keys.Count == 0 ? Endorsement.None : new Endorsement(KeyList.ToEndorsements()),
         _ => throw new InvalidOperationException($"Unknown Key Type {KeyCase}.  Do we have a network/library version mismatch?"),
     });
예제 #3
0
        public void EquivalentContractEndorsementsAreConsideredEqual()
        {
            var contract = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000));
            var bytes    = Abi.EncodeAddressPart(contract);

            var endorsement1 = new Endorsement(KeyType.Contract, bytes);
            var endorsement2 = new Endorsement(KeyType.Contract, bytes);

            Assert.Equal(endorsement1, endorsement2);
            Assert.True(endorsement1 == endorsement2);
            Assert.False(endorsement1 != endorsement2);

            object asObject1 = endorsement1;
            object asObject2 = endorsement2;

            Assert.Equal(asObject1, asObject2);
            Assert.True(endorsement1.Equals(asObject2));
            Assert.True(asObject1.Equals(endorsement2));
        }
예제 #4
0
        public async Task CanGetImutableStatefulContractInfo()
        {
            await using var fx = await StatefulContract.CreateAsync(_network, f =>
            {
                f.ContractParams.Administrator = null;
            });

            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);  // Assume for now they are equal
            Assert.NotNull(info.SmartContractId);
            // Immutable Contracts list their "contract" key as the administrator Key.
            Assert.Equal(KeyType.Contract, info.Administrator.Type);
            Assert.Equal(Abi.EncodeAddressPart(info.Contract).ToArray(), info.Administrator.PublicKey.ToArray());
            Assert.InRange(info.Expiration, DateTime.UtcNow, DateTime.MaxValue);
            Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod);
            Assert.InRange(info.Size, 0, fx.FileParams.Contents.Length);
            Assert.StartsWith(fx.ContractParams.Memo, info.Memo);
            Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance);
        }
예제 #5
0
        public void DisimilarContractEndorsementsAreConsideredNotEqual()
        {
            var contract1 = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000));
            var contract2 = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(20001, 50000));

            var bytes1 = Abi.EncodeAddressPart(contract1);
            var bytes2 = Abi.EncodeAddressPart(contract2);

            var endorsement1 = new Endorsement(KeyType.Contract, bytes1);
            var endorsement2 = new Endorsement(KeyType.Contract, bytes2);

            Assert.NotEqual(endorsement1, endorsement2);
            Assert.False(endorsement1 == endorsement2);
            Assert.True(endorsement1 != endorsement2);

            object asObject1 = endorsement1;
            object asObject2 = endorsement2;

            Assert.NotEqual(asObject1, asObject2);
            Assert.False(endorsement1.Equals(asObject2));
            Assert.False(asObject1.Equals(endorsement2));
        }