예제 #1
0
 private static bool SwapEndorsementsInTree(Endorsement original, Endorsement toRemove, Endorsement toAdd, out Endorsement revisedValue)
 {
     if (original != null)
     {
         if (original.Equals(toRemove))
         {
             revisedValue = toAdd;
             return(true);
         }
         else if (original.Type == KeyType.List)
         {
             var copy = original.List.ToArray();
             for (int i = 0; i < copy.Length; i++)
             {
                 if (SwapEndorsementsInTree(copy[i], toRemove, toAdd, out Endorsement revisedChild))
                 {
                     copy[i] = revisedChild;
                     copy    = copy.Where(e => e != null).ToArray();
                     var required = (uint)Math.Min(copy.Length, original.RequiredCount);
                     revisedValue = copy.Length > 0 ? new Endorsement(required, copy) : null;
                     return(true);
                 }
             }
         }
     }
     else if (toAdd != null)
     {
         revisedValue = toAdd;
         return(true);
     }
     revisedValue = original;
     return(false);
 }
예제 #2
0
    public void EquivalentContractEndorsementsAreConsideredEqual()
    {
        var contract = new Address(Generator.Integer(0, 100), Generator.Integer(0, 100), Generator.Integer(1000, 20000));

        var endorsement1 = new Endorsement(contract);
        var endorsement2 = new Endorsement(new Address(contract.ShardNum, contract.RealmNum, contract.AccountNum));

        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));
    }
예제 #3
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 endorsement1 = new Endorsement(contract1);
        var endorsement2 = new Endorsement(contract2);

        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));
    }
예제 #4
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));
        }
예제 #5
0
        public void EquivalentEndorsementsAreConsideredEqual()
        {
            var (publicKey1, _) = Generator.KeyPair();
            var (publicKey2, _) = Generator.KeyPair();
            var endorsement1 = new Endorsement(publicKey1);
            var endorsement2 = new Endorsement(publicKey1);
            Assert.Equal(endorsement1, endorsement2);
            Assert.True(endorsement1 == endorsement2);
            Assert.False(endorsement1 != endorsement2);

            endorsement1 = new Endorsement(publicKey1, publicKey2);
            endorsement2 = new Endorsement(publicKey1, publicKey2);
            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(asObject1));
            Assert.True(asObject1.Equals(endorsement1));
        }