Beispiel #1
0
        public async Task GetExecutive_With_SmartContractRegistrationProvider_Test()
        {
            var chain = await _smartContractHelper.CreateChainWithGenesisContractAsync();

            var chainContext = new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            //Get executive by smartContractRegistration in SmartContractRegistrationProvider
            await _smartContractRegistrationProvider.SetSmartContractRegistrationAsync(chainContext,
                                                                                       _defaultContractZeroCodeProvider.ContractZeroAddress,
                                                                                       _defaultContractZeroCodeProvider.DefaultContractZeroRegistration);

            var executive = await _smartContractExecutiveService
                            .GetExecutiveAsync(chainContext, _defaultContractZeroCodeProvider.ContractZeroAddress);

            executive.ContractHash.ShouldBe(_defaultContractZeroCodeProvider.DefaultContractZeroRegistration.CodeHash);

            await _smartContractExecutiveService.PutExecutiveAsync(chainContext,
                                                                   _defaultContractZeroCodeProvider.ContractZeroAddress, executive);

            //Get executive from executive pool
            executive = await _smartContractExecutiveService
                        .GetExecutiveAsync(chainContext, _defaultContractZeroCodeProvider.ContractZeroAddress);

            executive.ContractHash.ShouldBe(_defaultContractZeroCodeProvider.DefaultContractZeroRegistration.CodeHash);

            var otherExecutive = await _smartContractExecutiveService
                                 .GetExecutiveAsync(chainContext, _defaultContractZeroCodeProvider.ContractZeroAddress);

            await _smartContractExecutiveService.PutExecutiveAsync(chainContext,
                                                                   _defaultContractZeroCodeProvider.ContractZeroAddress, executive);

            await _smartContractExecutiveService.PutExecutiveAsync(chainContext,
                                                                   _defaultContractZeroCodeProvider.ContractZeroAddress, otherExecutive);

            _smartContractExecutiveProvider.GetExecutivePools()[_defaultContractZeroCodeProvider.ContractZeroAddress]
            .Count.ShouldBe(2);

            //Make codeHash different between smartContractRegistration and executive
            var code     = _smartContractHelper.Codes["AElf.Contracts.Configuration"];
            var codeHash = HashHelper.ComputeFrom(code);
            await _smartContractRegistrationProvider.SetSmartContractRegistrationAsync(chainContext,
                                                                                       _defaultContractZeroCodeProvider.ContractZeroAddress, new SmartContractRegistration
            {
                Category = KernelConstants.DefaultRunnerCategory,
                Code     = ByteString.CopyFrom(code),
                CodeHash = HashHelper.ComputeFrom(code)
            });

            executive = await _smartContractExecutiveService
                        .GetExecutiveAsync(chainContext, _defaultContractZeroCodeProvider.ContractZeroAddress);

            executive.ContractHash.ShouldBe(codeHash);
            _smartContractExecutiveProvider.GetExecutivePools()
            .TryGetValue(_defaultContractZeroCodeProvider.ContractZeroAddress, out _).ShouldBeFalse();
        }
        public async Task Put_ZeroRegistration_Executive_Success()
        {
            var registration = new SmartContractRegistration
            {
                Category = KernelConstants.DefaultRunnerCategory,
                Code     = Hash.FromString("TestPutExecutive").ToByteString(),
                CodeHash = Hash.FromString("TestPutExecutive")
            };

            var mockExecutive = new Mock <IExecutive>();
            await _smartContractExecutiveService.PutExecutiveAsync(SampleAddress.AddressList[7], mockExecutive.Object);
        }