Пример #1
0
        public void CreatePendingActivationsAfterRenewAdminState()
        {
            var random = new Random();
            var nonce  = new byte[40];

            random.NextBytes(nonce);
            var privateKey = new PrivateKey();

            var createPendingActivations = new CreatePendingActivations(new[]
            {
                new PendingActivationState(nonce, privateKey.PublicKey),
            });

            long blockIndex = _validUntil + 1;

            Assert.Throws <PolicyExpiredException>(() => createPendingActivations.Execute(new ActionContext
            {
                BlockIndex     = blockIndex,
                PreviousStates = _stateDelta,
                Signer         = _adminPrivateKey.ToAddress(),
            }));

            var newValidUntil = _validUntil + 1000;
            var action        = new RenewAdminState(newValidUntil);
            var stateDelta    = action.Execute(new ActionContext
            {
                BlockIndex     = blockIndex,
                PreviousStates = _stateDelta,
                Signer         = _adminPrivateKey.ToAddress(),
            });

            // After 100 blocks.
            blockIndex += 100;

            Assert.True(blockIndex < newValidUntil);
            stateDelta = createPendingActivations.Execute(new ActionContext
            {
                BlockIndex     = blockIndex,
                PreviousStates = stateDelta,
                Signer         = _adminPrivateKey.ToAddress(),
            });

            Address expectedPendingActivationStateAddress =
                PendingActivationState.DeriveAddress(nonce, privateKey.PublicKey);

            Assert.NotNull(stateDelta.GetState(expectedPendingActivationStateAddress));
        }
        public void PlainValue()
        {
            byte[]    nonce   = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            PublicKey pubKey  = new PrivateKey().PublicKey;
            Address   address = PendingActivationState.DeriveAddress(nonce, pubKey);
            var       pv      = new List()
                                .Add(new List(address.Serialize(), (Binary)nonce, pubKey.Serialize()));

            var action = new CreatePendingActivations();

            action.LoadPlainValue(pv);

            var pvFromAction         = Assert.IsType <List>(action.PlainValue);
            var activationFromAction = Assert.IsType <List>(pvFromAction[0]);

            Assert.Equal(address, new Address((Binary)activationFromAction[0]));
            Assert.Equal(nonce, (Binary)activationFromAction[1]);
            Assert.Equal(pubKey, new PublicKey(((Binary)activationFromAction[2]).ByteArray));
        }