public async Task SmartContractAddress_Get_WithHeightLargeThanLIB_Test() { await _smartContractHelper.CreateChainAsync(); var block = await _kernelTestHelper.AttachBlockToBestChain(); var chainContext = new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Height }; var contractName = Hash.Empty.ToStorageKey(); await _smartContractAddressService.SetSmartContractAddressAsync(chainContext, contractName, SampleAddress.AddressList[0]); var address = await _smartContractAddressService.GetAddressByContractNameAsync(chainContext, contractName); address.ShouldBe(SampleAddress.AddressList[0]); var smartContractAddressDto = await _smartContractAddressService.GetSmartContractAddressAsync(chainContext, contractName); smartContractAddressDto.SmartContractAddress.ShouldBe(new SmartContractAddress { Address = SampleAddress.AddressList[0], BlockHash = block.GetHash(), BlockHeight = block.Height }); smartContractAddressDto.Irreversible.ShouldBeFalse(); }
public async Task GetStateAsync_Test() { var chain = await _smartContractHelper.CreateChainAsync(); await Assert.ThrowsAsync <InvalidOperationException>(() => _smartContractBridgeService.GetStateAsync( SampleAddress.AddressList[0], string.Empty, chain.BestChainHeight, chain.BestChainHash)); var scopedStatePath = new ScopedStatePath { Address = SampleAddress.AddressList[0], Path = new StatePath { Parts = { "part" } } }; var state = await _smartContractBridgeService.GetStateAsync(SampleAddress.AddressList[0], scopedStatePath.ToStateKey(), chain.BestChainHeight, chain.BestChainHash); state.ShouldBeNull(); var blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash); blockStateSet.Changes[scopedStatePath.ToStateKey()] = ByteString.Empty; await _blockStateSetManger.SetBlockStateSetAsync(blockStateSet); state = await _smartContractBridgeService.GetStateAsync(SampleAddress.AddressList[0], scopedStatePath.ToStateKey(), chain.BestChainHeight, chain.BestChainHash); state.ShouldBe(ByteString.Empty); }
public async Task SmartContractAddress_Set_And_Get_Test() { var chain = await _smartContractHelper.CreateChainAsync(); var contractName = Hash.Empty.ToStorageKey(); var chainContext = new ChainContext { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }; var smartContractAddress = await _smartContractAddressProvider.GetSmartContractAddressAsync(chainContext, contractName); smartContractAddress.ShouldBeNull(); await _smartContractAddressProvider.SetSmartContractAddressAsync(chainContext, contractName, SampleAddress.AddressList[0]); var blockExecutedDataKey = $"BlockExecutedData/SmartContractAddress/{contractName}"; var blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash); blockStateSet.BlockExecutedData.ShouldContainKey(blockExecutedDataKey); smartContractAddress = await _smartContractAddressProvider.GetSmartContractAddressAsync(chainContext, contractName); smartContractAddress.Address.ShouldBe(SampleAddress.AddressList[0]); smartContractAddress.BlockHeight = chainContext.BlockHeight; smartContractAddress.BlockHash = chainContext.BlockHash; }
public async Task SmartContractRegistrationSetAndGet_Test() { var chain = await _smartContractHelper.CreateChainAsync(); var blockExecutedDataKey = $"BlockExecutedData/SmartContractRegistration/{SampleAddress.AddressList[0]}"; var chainContext = new ChainContext { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }; var smartContractRegistrationFromProvider = await _smartContractRegistrationProvider.GetSmartContractRegistrationAsync(chainContext, SampleAddress.AddressList[0]); smartContractRegistrationFromProvider.ShouldBeNull(); var smartContractRegistration = new SmartContractRegistration { CodeHash = HashHelper.ComputeFrom(blockExecutedDataKey), Category = KernelConstants.CodeCoverageRunnerCategory, Version = 1 }; await _smartContractRegistrationProvider.SetSmartContractRegistrationAsync(chainContext, SampleAddress.AddressList[0], smartContractRegistration); var blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash); blockStateSet.BlockExecutedData.ShouldContainKey(blockExecutedDataKey); smartContractRegistrationFromProvider = await _smartContractRegistrationProvider.GetSmartContractRegistrationAsync(chainContext, SampleAddress.AddressList[0]); smartContractRegistrationFromProvider.ShouldBe(smartContractRegistration); }