Exemplo n.º 1
0
 protected ContractParameterSerializationTests(T fixture)
 {
     this.mockChain  = fixture.Chain;
     this.node1      = this.mockChain.Nodes[0];
     this.node2      = this.mockChain.Nodes[1];
     this.serializer = new ContractPrimitiveSerializer(this.node1.CoreNode.FullNode.Network);
 }
        protected PoAMockChainFixture(int nodeNum)
        {
            var network = new SmartContractsPoARegTest();

            this.builder = SmartContractNodeBuilder.Create(this);

            CoreNode factory(int nodeIndex) => this.builder.CreateSmartContractPoANode(network, nodeIndex).Start();

            PoAMockChain mockChain = new PoAMockChain(2, factory).Build();

            this.Chain = mockChain;
            MockChainNode node1 = this.Chain.Nodes[0];
            MockChainNode node2 = this.Chain.Nodes[1];

            // Get premine
            mockChain.MineBlocks(10);

            // Send half to other from whoever received premine
            if ((long)node1.WalletSpendableBalance == node1.CoreNode.FullNode.Network.Consensus.PremineReward.Satoshi)
            {
                this.PayHalfPremine(node1, node2);
            }
            else
            {
                this.PayHalfPremine(node2, node1);
            }
        }
 protected ContractExecutionFailureTests(T fixture)
 {
     this.mockChain       = fixture.Chain;
     this.node1           = this.mockChain.Nodes[0];
     this.node2           = this.mockChain.Nodes[1];
     this.senderRetriever = new SenderRetriever();
 }
        protected PoAMockChainFixture(int nodeNum)
        {
            var network = new SmartContractsPoARegTest();

            // TODO: The PoA tests seem to use the same network class to do sets of tests with different rule requirements (signed/unsigned). Need to normalise it to avoid this hack.
            network.Consensus.MempoolRules.Remove(typeof(AllowedCodeHashLogicMempoolRule));

            this.builder = SmartContractNodeBuilder.Create(this);

            CoreNode factory(int nodeIndex) => this.builder.CreateSmartContractPoANode(network, nodeIndex).Start();

            PoAMockChain mockChain = new PoAMockChain(nodeNum, factory).Build();

            this.Chain = mockChain;
            MockChainNode node1 = this.Chain.Nodes[0];
            MockChainNode node2 = this.Chain.Nodes[1];

            // Get premine
            mockChain.MineBlocks(10);

            // Send half to other from whoever received premine
            if ((long)node1.WalletSpendableBalance == node1.CoreNode.FullNode.Network.Consensus.PremineReward.Satoshi)
            {
                this.PayHalfPremine(node1, node2);
            }
            else
            {
                this.PayHalfPremine(node2, node1);
            }
        }
 protected ContractInternalTransferTests(T fixture)
 {
     this.mockChain        = fixture.Chain;
     this.node1            = this.mockChain.Nodes[0];
     this.node2            = this.mockChain.Nodes[1];
     this.addressGenerator = new AddressGenerator();
     this.senderRetriever  = new SenderRetriever();
 }
 public static void WhitelistCode(this IMockChain chain, byte[] code)
 {
     foreach (MockChainNode node in chain.Nodes)
     {
         var hasher = node.CoreNode.FullNode.NodeService <IContractCodeHashingStrategy>();
         var hash   = new uint256(hasher.Hash(code));
         node.CoreNode.FullNode.NodeService <IWhitelistedHashesRepository>().AddHash(hash);
     }
 }
Exemplo n.º 7
0
        public PoWMockChainFixture()
        {
            this.Chain = new PoWMockChain(2);
            var node1    = this.Chain.Nodes[0];
            var node2    = this.Chain.Nodes[1];
            var maturity = (int)node1.CoreNode.FullNode.Network.Consensus.CoinbaseMaturity;

            // Fund both nodes with the minimum to have something to spend.
            node1.MineBlocks(maturity + 1);
            node2.MineBlocks(maturity + 1);
        }
Exemplo n.º 8
0
        private void SetupNodes(IMockChain chain, MockChainNode node1, MockChainNode node2)
        {
            // Get premine
            chain.MineBlocks(10);

            // Send half to other from whoever received premine
            if ((long)node1.WalletSpendableBalance == node1.CoreNode.FullNode.Network.Consensus.PremineReward.Satoshi)
            {
                PayHalfPremine(chain, node1, node2);
            }
            else
            {
                PayHalfPremine(chain, node2, node1);
            }
        }
        public MockChainNode(CoreNode coreNode, IMockChain chain, Mnemonic mnemonic = null)
        {
            this.CoreNode = coreNode;
            this.chain    = chain;

            // Set up address and mining
            this.CoreNode.FullNode.WalletManager().CreateWallet(this.Password, this.WalletName, this.Passphrase, mnemonic);
            this.MinerAddress = this.CoreNode.FullNode.WalletManager().GetUnusedAddress(new WalletAccountReference(this.WalletName, this.AccountName));
            Wallet wallet = this.CoreNode.FullNode.WalletManager().GetWalletByName(this.WalletName);
            Key    key    = wallet.GetExtendedPrivateKeyForAddress(this.Password, this.MinerAddress).PrivateKey;

            this.CoreNode.SetMinerSecret(new BitcoinSecret(key, this.CoreNode.FullNode.Network));

            // Set up services for later
            this.smartContractWalletController = this.CoreNode.FullNode.NodeController <SmartContractWalletController>();
            this.smartContractsController      = this.CoreNode.FullNode.NodeController <SmartContractsController>();
            this.stateRoot  = this.CoreNode.FullNode.NodeService <IStateRepositoryRoot>();
            this.blockStore = this.CoreNode.FullNode.NodeService <IBlockStore>();
        }
Exemplo n.º 10
0
        public PoAMockChainFixture()
        {
            PoAMockChain mockChain = new PoAMockChain(2).Build();

            this.Chain = mockChain;
            MockChainNode node1 = this.Chain.Nodes[0];
            MockChainNode node2 = this.Chain.Nodes[1];

            // Get premine
            mockChain.MineBlocks(10);

            // Send half to other from whoever received premine
            if ((long)node1.WalletSpendableBalance == node1.CoreNode.FullNode.Network.Consensus.PremineReward.Satoshi)
            {
                this.PayHalfPremine(node1, node2);
            }
            else
            {
                this.PayHalfPremine(node2, node1);
            }
        }
 public ContractPoAStressTests(PoAMockChainFixture3Nodes fixture)
 {
     this.mockChain = fixture.Chain;
 }
Exemplo n.º 12
0
 private void PayHalfPremine(IMockChain chain, MockChainNode from, MockChainNode to)
 {
     from.SendTransaction(to.MinerAddress.ScriptPubKey, new Money(from.CoreNode.FullNode.Network.Consensus.PremineReward.Satoshi / 2, MoneyUnit.Satoshi));
     from.WaitMempoolCount(1);
     chain.MineBlocks(1);
 }