コード例 #1
0
        public void EnsureCanonical_should_change_tx_blockhash([Values(false, true)] bool ensureCanonical)
        {
            (Block block, TxReceipt[] receipts) = InsertBlock();
            _storage.FindBlockHash(receipts[0].TxHash !).Should().Be(block.Hash !);

            Block anotherBlock = Build.A.Block
                                 .WithTransactions(block.Transactions)
                                 .WithReceiptsRoot(TestItem.KeccakA)
                                 .WithExtraData(new byte[] { 1 })
                                 .TestObject;

            anotherBlock.Hash.Should().NotBe(block.Hash !);
            _storage.Insert(anotherBlock, new [] { Build.A.Receipt.TestObject }, ensureCanonical);

            Keccak findBlockHash = _storage.FindBlockHash(receipts[0].TxHash !);

            if (ensureCanonical)
            {
                findBlockHash.Should().Be(anotherBlock.Hash !);
            }
            else
            {
                findBlockHash.Should().NotBe(anotherBlock.Hash !);
            }
        }
コード例 #2
0
        public async Task Cannot_make_deposit_with_wrong_value()
        {
            Address account = _wallet.GetAccounts()[0];
            Keccak  result  = await _depositManager.MakeAsync(_asset.Id, _asset.MinUnits, _asset.MinUnits *_asset.UnitPrice - 1, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #3
0
        public async Task Cannot_make_deposit_above_max_units()
        {
            Address account = _wallet.GetAccounts()[0];
            Keccak  result  = await _depositManager.MakeAsync(_asset.Id, _asset.MaxUnits + 1, (_asset.MaxUnits + 1) *_asset.UnitPrice, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #4
0
        public async Task Cannot_make_deposit_on_closed_asset()
        {
            Address account = _wallet.GetAccounts()[0];
            Keccak  result  = await _depositManager.MakeAsync(_closedAsset.Id, _closedAsset.MinUnits, _closedAsset.MinUnits *_closedAsset.UnitPrice, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #5
0
        public async Task Cannot_make_deposit_on_unknown_asset()
        {
            Address account = _wallet.GetAccounts()[0];
            Keccak  result  = await _depositManager.MakeAsync(Keccak.Compute("unknown"), _asset.MinUnits, _asset.MinUnits *_asset.UnitPrice, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #6
0
        public async Task Cannot_request_when_provider_is_missing()
        {
            _providerService.Remove(_providerId);
            Keccak id = await _service.RequestAsync(_newPendingAssetId, _consumerAddress, "kyc");

            id.Should().BeNull();
        }
コード例 #7
0
        public async Task Can_make_deposit_when_asset_is_under_maintenance()
        {
            Address account = _wallet.GetAccounts()[0];
            Keccak  result  = await _depositManager.MakeAsync(_assetUnderMaintenance.Id, _assetUnderMaintenance.MinUnits, _assetUnderMaintenance.MinUnits *_assetUnderMaintenance.UnitPrice, account, 20.GWei());

            result.Should().NotBeNull();
        }
コード例 #8
0
        public void Returns_null_for_missing_tx()
        {
            MemColumnsDb <ReceiptsColumns> receiptsDb = new MemColumnsDb <ReceiptsColumns>();
            PersistentReceiptStorage       persistentReceiptStorage = new PersistentReceiptStorage(receiptsDb, MainnetSpecProvider.Instance, new ReceiptsRecovery());
            Keccak blockHash = persistentReceiptStorage.FindBlockHash(Keccak.Zero);

            blockHash.Should().BeNull();
        }
コード例 #9
0
        public async Task Cannot_make_deposit_when_kyc_is_not_satisfied()
        {
            Address account = _wallet.GetAccounts()[0];

            _kycVerifier.IsVerifiedAsync(null, null).ReturnsForAnyArgs(false);
            Keccak result = await _depositManager.MakeAsync(_withKyc.Id, _withKyc.MinUnits, _withKyc.MinUnits *_withKyc.UnitPrice, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #10
0
        public async Task Cannot_make_deposit_when_address_is_locked()
        {
            Address account = _wallet.GetAccounts()[0];

            _wallet.LockAccount(account);
            Keccak result = await _depositManager.MakeAsync(_asset.Id, 1000, 1, account, 20.GWei());

            result.Should().BeNull();
        }
コード例 #11
0
        public async Task Can_request()
        {
            Keccak id = await _service.RequestAsync(_newPendingAssetId, _consumerAddress, "kyc");

            id.Should().NotBeNull();

            var result = await _service.BrowseAsync(new GetConsumerDepositApprovals());

            result.Items.Should().HaveCount(4);
        }
コード例 #12
0
        public async Task Ignore_approve_on_approved()
        {
            Keccak id = await _service.RequestAsync(_confirmedAssetId, _consumerAddress, "kyc");

            id.Should().NotBeNull();

            await _service.ConfirmAsync(_confirmedAssetId, _consumerAddress);

            var result = await _service.BrowseAsync(new GetConsumerDepositApprovals());

            result.Items.Where(i => i.State == DepositApprovalState.Confirmed).Should().HaveCount(1);
        }
コード例 #13
0
        public async Task Can_reject()
        {
            Keccak id = await _service.RequestAsync(_pendingAssetId, _consumerAddress, "kyc");

            id.Should().NotBeNull();

            await _service.RejectAsync(_pendingAssetId, _consumerAddress);

            var result = await _service.BrowseAsync(new GetConsumerDepositApprovals());

            result.Items.Where(i => i.State == DepositApprovalState.Rejected).Should().HaveCount(2);
        }
コード例 #14
0
        public async Task newBlock_accepts_previously_assembled_block_multiple_times([Values(1, 3)] int times)
        {
            using MergeTestBlockchain chain = await CreateBlockChain();

            IConsensusRpcModule rpc           = CreateConsensusModule(chain);
            Keccak               startingHead = chain.BlockTree.HeadHash;
            BlockHeader          startingBestSuggestedHeader        = chain.BlockTree.BestSuggestedHeader !;
            AssembleBlockRequest assembleBlockRequest               = new() { ParentHash = startingHead };
            ResultWrapper <BlockRequestResult?> assembleBlockResult = await rpc.consensus_assembleBlock(assembleBlockRequest);

            assembleBlockResult.Data !.ParentHash.Should().Be(startingHead);

            for (int i = 0; i < times; i++)
            {
                ResultWrapper <NewBlockResult> newBlockResult = await rpc.consensus_newBlock(assembleBlockResult.Data !);

                newBlockResult.Data.Valid.Should().BeTrue();
            }

            Keccak bestSuggestedHeaderHash = chain.BlockTree.BestSuggestedHeader !.Hash !;

            bestSuggestedHeaderHash.Should().Be(assembleBlockResult.Data !.BlockHash);
            bestSuggestedHeaderHash.Should().NotBe(startingBestSuggestedHeader !.Hash !);
        }
コード例 #15
0
        public async Task setHead_should_change_head()
        {
            using MergeTestBlockchain chain = await CreateBlockChain();

            IConsensusRpcModule rpc = CreateConsensusModule(chain);
            Keccak startingHead     = chain.BlockTree.HeadHash;

            BlockRequestResult blockRequestResult = CreateBlockRequest(
                CreateParentBlockRequestOnHead(chain.BlockTree),
                TestItem.AddressD);
            ResultWrapper <NewBlockResult> newBlockResult = await rpc.consensus_newBlock(blockRequestResult);

            newBlockResult.Data.Valid.Should().BeTrue();

            Keccak newHeadHash = blockRequestResult.BlockHash;
            ResultWrapper <Result> setHeadResult = await rpc.consensus_setHead(newHeadHash !);

            setHeadResult.Data.Should().Be(Result.OK);

            Keccak actualHead = chain.BlockTree.HeadHash;

            actualHead.Should().NotBe(startingHead);
            actualHead.Should().Be(newHeadHash);
        }
コード例 #16
0
        public void Can_get_root(uint nodesCount)
        {
            BaselineTree baselineTree = BuildATree();
            Keccak       root         = baselineTree.Root;

            Console.WriteLine(root);
            for (int i = 0; i < nodesCount; i++)
            {
                baselineTree.Insert(_testLeaves[0]);
                Keccak newRoot = baselineTree.Root;
                Console.WriteLine(newRoot);
                newRoot.Should().NotBeEquivalentTo(root);
                root = newRoot;
            }
        }
コード例 #17
0
        public void Test_out_of_gas_existing_account_with_storage()
        {
            byte[] salt         = { 4, 5, 6 };
            byte[] deployedCode = { 1, 2, 3 };

            byte[] initCode = Prepare.EvmCode
                              .ForInitOf(deployedCode).Done;

            byte[] createCode = Prepare.EvmCode
                                .Create2(initCode, salt, 0).Done;

            Address expectedAddress = ContractAddress.From(TestItem.AddressC, salt.PadLeft(32).AsSpan(), initCode.AsSpan());

            TestState.CreateAccount(expectedAddress, 1.Ether());
            Storage.Set(new StorageCell(expectedAddress, 1), new byte[] { 1, 2, 3, 4, 5 });
            Storage.Commit();
            Storage.CommitTrees();
            TestState.Commit(Spec);
            TestState.CommitTree();

            Keccak storageRoot = TestState.GetAccount(expectedAddress).StorageRoot;

            storageRoot.Should().NotBe(PatriciaTree.EmptyTreeHash);

            TestState.CreateAccount(TestItem.AddressC, 1.Ether());

            Keccak createCodeHash = TestState.UpdateCode(createCode);

            TestState.UpdateCodeHash(TestItem.AddressC, createCodeHash, Spec);

            byte[] code = Prepare.EvmCode
                          .Call(TestItem.AddressC, 32100)
                          .Done;

            Execute(code);

            TestState.GetAccount(expectedAddress).Should().NotBeNull();
            TestState.GetAccount(expectedAddress).Balance.Should().Be(1.Ether());
            TestState.GetAccount(expectedAddress).StorageRoot.Should().Be(storageRoot);
            AssertEip1014(expectedAddress, Bytes.Empty);
        }
コード例 #18
0
        public void Can_verify_zero_and_one_elements(uint nodesCount)
        {
            BaselineTree baselineTree = BuildATree();
            Keccak       root         = baselineTree.Root;

            Console.WriteLine(root);
            for (int i = 0; i < nodesCount; i++)
            {
                baselineTree.Insert(_testLeaves[i]);
                Keccak newRoot = baselineTree.Root;
                Console.WriteLine(newRoot);
                newRoot.Should().NotBeEquivalentTo(root);
                root = newRoot;
                var proof0 = baselineTree.GetProof(0);
                var proof1 = baselineTree.GetProof(1);
                baselineTree.Verify(root, _testLeaves[0], proof0).Should().BeTrue("left in " + i);
                if (i > 0)
                {
                    baselineTree.Verify(root, _testLeaves[1], proof1).Should().BeTrue("right in " + i);
                }
            }
        }
コード例 #19
0
        public async Task Various_ignored_cases()
        {
            await _service.ConfirmAsync(_confirmedApproval.AssetId, _consumerAddress);

            await _service.RejectAsync(_rejectedApproval.AssetId, _consumerAddress);

            await _service.ConfirmAsync(Keccak.Compute("unknown"), _consumerAddress);

            await _service.RejectAsync(Keccak.Compute("unknown"), _consumerAddress);

            Keccak unknownAssetIdResult = await _service.RequestAsync(Keccak.Compute("unknown"), _consumerAddress, "kyc");

            unknownAssetIdResult.Should().BeNull();
            Keccak nullKycResult = await _service.RequestAsync(_newPendingAssetId, _consumerAddress, null);

            nullKycResult.Should().BeNull();
            Keccak emptyKycResult = await _service.RequestAsync(_newPendingAssetId, _consumerAddress, string.Empty);

            emptyKycResult.Should().BeNull();
            Keccak tooLongKycResult = await _service.RequestAsync(_newPendingAssetId, _consumerAddress, new byte[32 * 1024 / 2 + 1].ToHexString());

            tooLongKycResult.Should().BeNull();
        }
コード例 #20
0
        public void Returns_null_for_missing_tx()
        {
            Keccak blockHash = _storage.FindBlockHash(Keccak.Zero);

            blockHash.Should().BeNull();
        }