Exemplo n.º 1
0
        // Checks that node can sync from scratch if federation voted in favor of adding a new fed member.
        public async Task CanSyncIfFedMemberAddedAsync()
        {
            int originalFedMembersCount = this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count;

            TestHelper.Connect(this.node1, this.node2);

            var model = new HexPubKeyModel()
            {
                PubKeyHex = "03025fcadedd28b12665de0542c8096f4cd5af8e01791a4d057f67e2866ca66ba7"
            };

            this.node1.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);
            this.node2.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);

            await this.node1.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            await this.node2.MineBlocksAsync((int)this.network.Consensus.MaxReorgLength * 3);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            Assert.Equal(originalFedMembersCount + 1, this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count);

            TestHelper.Connect(this.node2, this.node3);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2, this.node3);
        }
Exemplo n.º 2
0
        // Checks that node can sync from scratch if federation voted in favor of kicking a fed member.
        public async Task CanSyncIfFedMemberKickedAsync()
        {
            int originalFedMembersCount = this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count;

            TestHelper.Connect(this.node1, this.node2);

            var model = new HexPubKeyModel()
            {
                PubKeyHex = this.network.FederationKey2.PubKey.ToHex()
            };

            this.node1.FullNode.NodeService <FederationVotingController>().VoteKickFedMember(model);
            this.node2.FullNode.NodeService <FederationVotingController>().VoteKickFedMember(model);

            await this.node2.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            await this.node1.MineBlocksAsync((int)this.network.Consensus.MaxReorgLength * 3);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            Assert.Equal(originalFedMembersCount - 1, this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count);

            TestHelper.Connect(this.node2, this.node3);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2, this.node3);
        }
Exemplo n.º 3
0
        public async Task ReorgRevertsAppliedChangesAsync()
        {
            TestHelper.Connect(this.node1, this.node2);

            var model = new HexPubKeyModel()
            {
                PubKeyHex = this.testPubKey.ToHex()
            };

            this.node1.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);
            this.node1.FullNode.NodeService <FederationVotingController>().VoteKickFedMember(model);
            await this.node1.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            this.node2.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);
            await this.node2.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            Assert.Single(this.node2.FullNode.NodeService <VotingManager>().GetPendingPolls());
            Assert.Single(this.node2.FullNode.NodeService <VotingManager>().GetFinishedPolls());

            await this.node3.MineBlocksAsync(4);

            TestHelper.Connect(this.node2, this.node3);
            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2, this.node3);

            Assert.Empty(this.node2.FullNode.NodeService <VotingManager>().GetPendingPolls());
            Assert.Empty(this.node2.FullNode.NodeService <VotingManager>().GetFinishedPolls());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Votes to add a federation member.
        /// </summary>
        /// <param name="request">Request containing member public key</param>
        /// <returns></returns>
        public void VoteAddFedMember(HexPubKeyModel request)
        {
            var path = "/api/FederationVoting/schedulevote-addfedmember";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            postBody = ApiClient.Serialize(request);                                     // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VoteAddFedMember: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VoteAddFedMember: " + response.ErrorMessage, response.ErrorMessage);
            }

            return;
        }
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>Task of ApiResponse</returns>
        public async System.Threading.Tasks.Task <ApiResponse <Object> > VoteKickFedMemberAsyncWithHttpInfo(HexPubKeyModel request = null)
        {
            var    localVarPath         = "/api/FederationVoting/schedulevote-kickfedmember";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
            };
            String localVarHttpHeaderAccept    = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (request != null && request.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("VoteKickFedMember", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            null));
        }
        // Checks that multisig fed members can't be kicked.
        public async Task CantKickMultiSigFedMemberAsync()
        {
            var      network = new TestPoACollateralNetwork();
            CoreNode node    = this.builder.CreatePoANode(network, network.FederationKey1).Start();

            var model = new HexPubKeyModel()
            {
                PubKeyHex = network.FederationKey2.PubKey.ToHex()
            };
            IActionResult response = node.FullNode.NodeController <FederationVotingController>().VoteKickFedMember(model);

            Assert.True(response is ErrorResult errorResult && errorResult.Value is ErrorResponse errorResponse && errorResponse.Errors.First().Message == "Multisig members can't be voted on");
        }
Exemplo n.º 7
0
        // Checks that fed members cant vote twice.
        // Checks that miner adds voting data if it exists.
        public async Task CantVoteTwiceAsync()
        {
            int originalFedMembersCount = this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count;

            TestHelper.Connect(this.node1, this.node2);

            await this.node1.MineBlocksAsync(3);

            var model = new HexPubKeyModel()
            {
                PubKeyHex = "03025fcadedd28b12665de0542c8096f4cd5af8e01791a4d057f67e2866ca66ba7"
            };

            this.node1.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);

            Assert.Single(this.node1.FullNode.NodeService <VotingManager>().GetScheduledVotes());
            Assert.Empty(this.node1.FullNode.NodeService <VotingManager>().GetPendingPolls());

            await this.node1.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            Assert.Empty(this.node1.FullNode.NodeService <VotingManager>().GetScheduledVotes());
            Assert.Single(this.node1.FullNode.NodeService <VotingManager>().GetPendingPolls());

            // Vote 2nd time and make sure nothing changed.
            this.node1.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);
            await this.node1.MineBlocksAsync(1);

            Assert.Empty(this.node1.FullNode.NodeService <VotingManager>().GetScheduledVotes());
            Assert.Single(this.node1.FullNode.NodeService <VotingManager>().GetPendingPolls());

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            // Node 2 votes. After that it will be enough to change the federation.
            this.node2.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);

            await this.node2.MineBlocksAsync((int)this.network.Consensus.MaxReorgLength + 1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2);

            Assert.Equal(originalFedMembersCount + 1, this.node1.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count);
            Assert.Equal(originalFedMembersCount + 1, this.node2.FullNode.NodeService <IFederationManager>().GetFederationMembers().Count);

            TestHelper.Connect(this.node2, this.node3);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2, this.node3);
        }
Exemplo n.º 8
0
        private async Task VoteAndMineBlockAsync(PubKey key, bool add, CoreNode node)
        {
            var model = new HexPubKeyModel()
            {
                PubKeyHex = key.ToHex()
            };

            if (add)
            {
                node.FullNode.NodeService <FederationVotingController>().VoteAddFedMember(model);
            }
            else
            {
                node.FullNode.NodeService <FederationVotingController>().VoteKickFedMember(model);
            }

            await node.MineBlocksAsync(1);

            CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2, this.node3);
        }
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task VoteKickFedMemberAsync(HexPubKeyModel request = null)
 {
     await VoteKickFedMemberAsyncWithHttpInfo(request);
 }
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns></returns>
 public void VoteKickFedMember(HexPubKeyModel request = null)
 {
     VoteKickFedMemberWithHttpInfo(request);
 }