コード例 #1
0
        public void finalize_change_should_call_correct_transaction()
        {
            var expectation = new SystemTransaction()
            {
                Value         = 0,
                Data          = new byte[] { 0x75, 0x28, 0x62, 0x11 },
                Hash          = new Keccak("0x0652461cead47b6e1436fc631debe06bde8bcdd2dad3b9d21df5cf092078c6d3"),
                To            = _contractAddress,
                SenderAddress = Address.SystemUser,
                GasLimit      = Blockchain.Contracts.CallableContract.UnlimitedGas,
                GasPrice      = 0,
                Nonce         = 0
            };

            expectation.Hash = expectation.CalculateHash();

            var contract = new ValidatorContract(
                _transactionProcessor,
                new AbiEncoder(),
                _contractAddress,
                _stateProvider,
                _readOnlyTransactionProcessorSource,
                new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance));

            contract.FinalizeChange(_block.Header);

            _transactionProcessor.Received().Execute(
                Arg.Is <Transaction>(t => IsEquivalentTo(expectation, t)), _block.Header, Arg.Any <ITxTracer>());
        }
コード例 #2
0
ファイル: GenesisLoader.cs プロジェクト: prestwich/nethermind
        public Block Load()
        {
            Block genesis = _chainSpec.Genesis;

            foreach ((Address address, ChainSpecAllocation allocation) in _chainSpec.Allocations.OrderBy(a => a.Key))
            {
                _stateProvider.CreateAccount(address, allocation.Balance);

                if (allocation.Code != null)
                {
                    Keccak codeHash = _stateProvider.UpdateCode(allocation.Code);
                    _stateProvider.UpdateCodeHash(address, codeHash, _specProvider.GenesisSpec);
                }

                if (allocation.Storage != null)
                {
                    foreach (KeyValuePair <UInt256, byte[]> storage in allocation.Storage)
                    {
                        _storageProvider.Set(new StorageCell(address, storage.Key), storage.Value.WithoutLeadingZeros().ToArray());
                    }
                }

                if (allocation.Constructor != null)
                {
                    Transaction constructorTransaction = new SystemTransaction()
                    {
                        SenderAddress = address,
                        Init          = allocation.Constructor,
                        GasLimit      = genesis.GasLimit
                    };

                    CallOutputTracer outputTracer = new CallOutputTracer();
                    _transactionProcessor.Execute(constructorTransaction, genesis.Header, outputTracer);

                    if (outputTracer.StatusCode != StatusCode.Success)
                    {
                        throw new InvalidOperationException($"Failed to initialize constructor for address {address}. Error: {outputTracer.Error}");
                    }
                }
            }

            // we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet
            _chainSpec.Allocations = null;

            _storageProvider.Commit();
            _stateProvider.Commit(_specProvider.GenesisSpec);

            _storageProvider.CommitTrees();
            _stateProvider.CommitTree();

            _dbProvider.StateDb.Commit();
            _dbProvider.CodeDb.Commit();

            genesis.Header.StateRoot = _stateProvider.StateRoot;
            genesis.Header.Hash      = genesis.Header.CalculateHash();

            return(genesis);
        }
コード例 #3
0
        public void TryCalculatePremiumPerGas_should_succeeds_for_free_transactions()
        {
            Transaction transaction = new SystemTransaction();

            transaction.DecodedMaxFeePerGas = 10;
            transaction.GasPrice            = 30;
            transaction.Type = TxType.EIP1559;
            bool tryResult = transaction.TryCalculatePremiumPerGas(100, out UInt256 premiumPerGas);

            Assert.AreEqual(UInt256.Zero, premiumPerGas);
            Assert.True(tryResult);
        }
コード例 #4
0
        public Block Load()
        {
            Block genesis = _chainSpec.Genesis;

            foreach ((Address address, ChainSpecAllocation allocation) in _chainSpec.Allocations)
            {
                _stateProvider.CreateAccount(address, allocation.Balance);
                if (allocation.Code != null)
                {
                    Keccak codeHash = _stateProvider.UpdateCode(allocation.Code);
                    _stateProvider.UpdateCodeHash(address, codeHash, _specProvider.GenesisSpec);
                }

                if (allocation.Constructor != null)
                {
                    Transaction constructorTransaction = new SystemTransaction()
                    {
                        SenderAddress = address,
                        Init          = allocation.Constructor,
                        GasLimit      = genesis.GasLimit
                    };

                    _transactionProcessor.Execute(constructorTransaction, genesis.Header, NullTxTracer.Instance);
                }
            }

            // we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet
            _chainSpec.Allocations = null;

            _storageProvider.Commit();
            _stateProvider.Commit(_specProvider.GenesisSpec);

            _storageProvider.CommitTrees();
            _stateProvider.CommitTree();

            _dbProvider.StateDb.Commit();
            _dbProvider.CodeDb.Commit();

            genesis.Header.StateRoot = _stateProvider.StateRoot;
            genesis.Header.Hash      = genesis.Header.CalculateHash();

            return(genesis);
        }
コード例 #5
0
        private void Preallocate(Block genesis)
        {
            foreach ((Address address, ChainSpecAllocation allocation) in _chainSpec.Allocations.OrderBy(a => a.Key))
            {
                _stateProvider.CreateAccount(address, allocation.Balance, allocation.Nonce);

                if (allocation.Code != null)
                {
                    Keccak codeHash = _stateProvider.UpdateCode(allocation.Code);
                    _stateProvider.UpdateCodeHash(address, codeHash, _specProvider.GenesisSpec);
                }

                if (allocation.Storage != null)
                {
                    foreach (KeyValuePair <UInt256, byte[]> storage in allocation.Storage)
                    {
                        _storageProvider.Set(new StorageCell(address, storage.Key),
                                             storage.Value.WithoutLeadingZeros().ToArray());
                    }
                }

                if (allocation.Constructor != null)
                {
                    Transaction constructorTransaction = new SystemTransaction()
                    {
                        SenderAddress = address,
                        Data          = allocation.Constructor,
                        GasLimit      = genesis.GasLimit
                    };

                    CallOutputTracer outputTracer = new();
                    _transactionProcessor.Execute(constructorTransaction, genesis.Header, outputTracer);

                    if (outputTracer.StatusCode != StatusCode.Success)
                    {
                        throw new InvalidOperationException(
                                  $"Failed to initialize constructor for address {address}. Error: {outputTracer.Error}");
                    }
                }
            }
        }
コード例 #6
0
 int IRlpDecoder <SystemTransaction> .GetLength(SystemTransaction item, RlpBehaviors rlpBehaviors) => GetLength(item, rlpBehaviors);
コード例 #7
0
 Rlp IRlpDecoder <SystemTransaction> .Encode(SystemTransaction item, RlpBehaviors rlpBehaviors) => Encode(item, rlpBehaviors);