Ejemplo n.º 1
0
        protected void Prepare()
        {
            _wallet          = new DevWallet(new WalletConfig(), _logManager);
            _feeAccount      = _wallet.GetAccounts()[0];
            _consumerAccount = _wallet.GetAccounts()[1];
            _providerAccount = _wallet.GetAccounts()[2];
            _ndmConfig       = new NdmConfig();

            IReleaseSpec  spec         = _releaseSpec;
            ISpecProvider specProvider = new SingleReleaseSpecProvider(spec, 99);
            StateDb       stateDb      = new StateDb();

            _state = new StateProvider(stateDb, new StateDb(), _logManager);
            StorageProvider storageProvider = new StorageProvider(stateDb, _state, _logManager);

            _state.CreateAccount(_consumerAccount, 1000.Ether());
            _state.CreateAccount(_providerAccount, 1.Ether());
            _state.Commit(spec);
            _state.CommitTree();

            VirtualMachine       machine   = new VirtualMachine(_state, storageProvider, Substitute.For <IBlockhashProvider>(), _logManager);
            TransactionProcessor processor = new TransactionProcessor(specProvider, _state, storageProvider, machine, _logManager);

            _bridge = new BlockchainBridge(processor, _releaseSpec);

            TxReceipt receipt = DeployContract(Bytes.FromHexString(ContractData.GetInitCode(_feeAccount)));

            _ndmConfig.ContractAddress = receipt.ContractAddress.ToString();
        }
Ejemplo n.º 2
0
        protected async Task Prepare()
        {
            _wallet          = new DevWallet(new WalletConfig(), _logManager);
            _feeAccount      = _wallet.GetAccounts()[0];
            _consumerAccount = _wallet.GetAccounts()[1];
            _providerAccount = _wallet.GetAccounts()[2];
            _ndmConfig       = new NdmConfig();

            IReleaseSpec  spec         = _releaseSpec;
            ISpecProvider specProvider = new SingleReleaseSpecProvider(spec, 99);
            StateDb       stateDb      = new StateDb();

            _state = new StateProvider(stateDb, new StateDb(), _logManager);
            StorageProvider storageProvider = new StorageProvider(stateDb, _state, _logManager);

            _state.CreateAccount(_consumerAccount, 1000.Ether());
            _state.CreateAccount(_providerAccount, 1.Ether());
            _state.Commit(spec);
            _state.CommitTree();

            VirtualMachine machine = new VirtualMachine(_state, storageProvider, Substitute.For <IBlockhashProvider>(),
                                                        specProvider, _logManager);
            TransactionProcessor processor = new TransactionProcessor(specProvider, _state, storageProvider, machine, _logManager);

            _bridge = new BlockchainBridge(processor);

            TxReceipt receipt = await DeployContract(Bytes.FromHexString(ContractData.GetInitCode(_feeAccount)));

            ((NdmConfig)_ndmConfig).ContractAddress = receipt.ContractAddress.ToString();
            _contractAddress = receipt.ContractAddress;
            _txPool          = new TxPool.TxPool(new InMemoryTxStorage(), Timestamper.Default,
                                                 new EthereumEcdsa(specProvider.ChainId, _logManager), specProvider, new TxPoolConfig(), _state, _logManager);
            _ndmBridge = new NdmBlockchainBridge(_bridge, _bridge, _bridge, _bridge);
        }
Ejemplo n.º 3
0
        public void Personal_list_accounts()
        {
            IPersonalModule module           = new PersonalModule(_ecdsa, _wallet, _keyStore);
            string          serialized       = RpcTest.TestSerializedRequest(module, "personal_listAccounts");
            string          expectedAccounts = string.Join(',', _wallet.GetAccounts().Select(a => $"\"{a.ToString()}\""));

            Assert.AreEqual($"{{\"jsonrpc\":\"2.0\",\"result\":[{expectedAccounts}],\"id\":67}}", serialized);
        }
Ejemplo n.º 4
0
        protected async Task Prepare()
        {
            _wallet          = new DevWallet(new WalletConfig(), _logManager);
            _feeAccount      = _wallet.GetAccounts()[0];
            _consumerAccount = _wallet.GetAccounts()[1];
            _providerAccount = _wallet.GetAccounts()[2];
            _ndmConfig       = new NdmConfig();

            IReleaseSpec  spec         = _releaseSpec;
            ISpecProvider specProvider = new SingleReleaseSpecProvider(spec, 99);
            MemDb         stateDb      = new MemDb();
            TrieStore     trieStore    = new TrieStore(stateDb, _logManager);

            _state = new StateProvider(trieStore, new MemDb(), _logManager);
            StorageProvider storageProvider = new StorageProvider(trieStore, _state, _logManager);

            _state.CreateAccount(_consumerAccount, 1000.Ether());
            _state.CreateAccount(_providerAccount, 1.Ether());
            _state.Commit(spec);
            _state.CommitTree(0);

            VirtualMachine machine =
                new VirtualMachine(Substitute.For <IBlockhashProvider>(), specProvider, _logManager);
            TransactionProcessor processor = new TransactionProcessor(specProvider, _state, storageProvider, machine, _logManager);

            _bridge = new BlockchainBridge(processor);

            TxReceipt receipt = await DeployContract(Bytes.FromHexString(ContractData.GetInitCode(_feeAccount)));

            ((NdmConfig)_ndmConfig).ContractAddress = receipt.ContractAddress.ToString();
            _contractAddress = receipt.ContractAddress;
            IBlockTree blockTree = Substitute.For <IBlockTree>();
            Block      block     = Build.A.Block.WithNumber(0).TestObject;

            blockTree.Head.Returns(block);
            TransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, blockTree);

            _txPool = new TxPool.TxPool(
                new EthereumEcdsa(specProvider.ChainId, _logManager),
                new ChainHeadInfoProvider(specProvider, blockTree, _state),
                new TxPoolConfig(),
                new TxValidator(specProvider.ChainId),
                _logManager,
                transactionComparerProvider.GetDefaultComparer());
            _ndmBridge = new NdmBlockchainBridge(_bridge, _bridge, _bridge, _bridge);
        }
Ejemplo n.º 5
0
        public void Each_account_can_sign_with_simple_key()
        {
            DevWallet wallet = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                byte[] keyBytes = new byte[32];
                keyBytes[31] = (byte)i;
                PrivateKey key = new PrivateKey(keyBytes);
                Assert.AreEqual(key.Address, wallet.GetAccounts()[i - 1], $"{i}");
            }
        }
Ejemplo n.º 6
0
        public void Can_sign()
        {
            EthereumSigner signer = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, 99), NullLogManager.Instance);
            DevWallet      wallet = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                Address   signerAddress = wallet.GetAccounts()[0];
                Signature sig           = wallet.Sign(signerAddress, TestObject.KeccakA);
                Address   recovered     = signer.RecoverAddress(sig, TestObject.KeccakA);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
            }
        }
Ejemplo n.º 7
0
        public void Setup()
        {
            IConfigManager configManager = Substitute.For <IConfigManager>();

            configManager.GetAsync(null).ReturnsForAnyArgs(new NdmConfig());
            IDataStreamService dataStreamService = Substitute.For <IDataStreamService>();

            _providerService = Substitute.For <IProviderService>();
            ISessionService sessionService = Substitute.For <ISessionService>();

            _ndmNotifier = Substitute.For <INdmNotifier>();
            IConsumerNotifier consumerNotifier = new ConsumerNotifier(_ndmNotifier);

            _wallet          = new DevWallet(new WalletConfig(), LimboLogs.Instance);
            _consumerAddress = _wallet.GetAccounts()[0];
            _accountService  = new AccountService(configManager, dataStreamService, _providerService, sessionService, consumerNotifier, _wallet, "configId", _consumerAddress, LimboLogs.Instance);
        }
Ejemplo n.º 8
0
        public void Can_sign_on_networks_with_chain_id()
        {
            const int      networkId = 40000;
            EthereumSigner signer    = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, networkId), NullLogManager.Instance);
            DevWallet      wallet    = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                Address     signerAddress = wallet.GetAccounts()[0];
                Transaction tx            = new Transaction();
                tx.SenderAddress = signerAddress;

                wallet.Sign(tx, networkId);
                Address recovered = signer.RecoverAddress(tx, networkId);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
                Assert.AreEqual(networkId, tx.Signature.GetChainId, "chainId");
            }
        }
Ejemplo n.º 9
0
        public void Has_10_dev_accounts()
        {
            DevWallet wallet = new DevWallet(NullLogManager.Instance);

            Assert.AreEqual(10, wallet.GetAccounts().Length);
        }