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)); }
public void Execute() { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); PendingActivationState CreatePendingActivation() { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var pubKey = new PrivateKey().PublicKey; return(new PendingActivationState(nonce, pubKey)); } PendingActivationState[] activations = Enumerable.Range(0, 5000).Select(_ => CreatePendingActivation()).ToArray(); var action = new CreatePendingActivations(activations); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); var state = new State(ImmutableDictionary <Address, IValue> .Empty .Add(AdminState.Address, adminState.Serialize()) ); var actionContext = new ActionContext() { BlockIndex = 1, PreviousStates = state, Signer = adminAddress, }; var nextState = action.Execute(actionContext); foreach (PendingActivationState pa in activations) { Assert.Equal( pa.Serialize(), nextState.GetState(pa.address) ); } }
public void CheckPermission() { var action = new CreatePendingActivations(); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); var state = new State(ImmutableDictionary <Address, IValue> .Empty .Add(AdminState.Address, adminState.Serialize()) ); Assert.Throws <PolicyExpiredException>( () => action.Execute(new ActionContext() { BlockIndex = 101, PreviousStates = state, Signer = adminAddress, }) ); Assert.Throws <PermissionDeniedException>( () => action.Execute(new ActionContext() { BlockIndex = 1, PreviousStates = state, Signer = default,