Пример #1
0
        public async Task get_code_should_invoke_blockchain_bridge_get_code()
        {
            var code    = new byte[] { 0, 1, 2 };
            var address = TestItem.AddressA;

            _blockchainBridge.GetCode(address).Returns(code);
            var result = await _ndmBridge.GetCodeAsync(address);

            _blockchainBridge.Received().GetCode(address);
            result.Should().BeSameAs(code);
        }
Пример #2
0
        public async Task get_code_should_invoke_blockchain_bridge_get_code()
        {
            var code    = new byte[] { 0, 1, 2 };
            var address = TestItem.AddressA;

            _stateReader.GetCode(Arg.Any <Keccak>(), address).Returns(code);
            _blockFinder.Head.Returns(_anyBlock);
            var result = await _ndmBridge.GetCodeAsync(address);

            _stateReader.Received().GetCode(_anyBlock.StateRoot, address);
            result.Should().BeSameAs(code);
        }
        public async Task get_code_should_invoke_proxy_get_code()
        {
            var code    = new byte[] { 0, 1, 2 };
            var address = TestItem.AddressA;

            _proxy.eth_getCode(address, Arg.Is <BlockParameterModel>(x => x.Type == BlockParameterModel.Latest.Type))
            .Returns(RpcResult <byte[]> .Ok(code));
            var result = await _ndmBridge.GetCodeAsync(address);

            await _proxy.Received().eth_getCode(address,
                                                Arg.Is <BlockParameterModel>(x => x.Type == BlockParameterModel.Latest.Type));

            result.Should().BeSameAs(code);
        }
Пример #4
0
        public async Task ValidateContractAddressAsync(Address contractAddress)
        {
            if (contractAddress != _contractAddress)
            {
                throw new InvalidDataException($"Contract address {contractAddress} is different than configured {_contractAddress}");
            }

            var code = await _blockchainBridge.GetCodeAsync(contractAddress);

            if (code is null || code.Length == 0)
            {
                throw new InvalidDataException($"No contract code at address {contractAddress}.");
            }

            if (!Bytes.AreEqual(code, Bytes.FromHexString(ContractData.DeployedCode)))
            {
                throw new InvalidDataException($"Code at address {contractAddress} is different than expected.");
            }
        }