Beispiel #1
0
        public void SmartContractExecutiveProvider_Test()
        {
            var address = SampleAddress.AddressList[0];

            _smartContractExecutiveProvider.TryGetValue(address, out var executives).ShouldBeFalse();
            executives.ShouldBeNull();
            _smartContractExecutiveProvider.TryRemove(address, out executives).ShouldBeFalse();
            executives.ShouldBeNull();

            var executivePools = _smartContractExecutiveProvider.GetExecutivePools();

            executivePools.Count.ShouldBe(0);
            var pool = _smartContractExecutiveProvider.GetPool(address);

            pool.Count.ShouldBe(0);
            _smartContractExecutiveProvider.TryGetValue(address, out executives).ShouldBeTrue();
            executives.ShouldBe(pool);
            executivePools = _smartContractExecutiveProvider.GetExecutivePools();
            executivePools.Count.ShouldBe(1);

            _smartContractExecutiveProvider.TryRemove(address, out executives).ShouldBeTrue();
            executives.ShouldBe(pool);
            _smartContractExecutiveProvider.TryGetValue(address, out executives).ShouldBeFalse();
            executives.ShouldBeNull();
        }
        public virtual async Task PutExecutiveAsync(IChainContext chainContext, Address address, IExecutive executive)
        {
            if (_smartContractExecutiveProvider.TryGetValue(address, out var pool))
            {
                var smartContractRegistration =
                    await _smartContractRegistrationProvider.GetSmartContractRegistrationAsync(chainContext, address);

                if (smartContractRegistration != null && smartContractRegistration.CodeHash == executive.ContractHash ||
                    chainContext.BlockHeight <= AElfConstants.GenesisBlockHeight)
                {
                    executive.LastUsedTime = TimestampHelper.GetUtcNow();
                    pool.Add(executive);
                    return;
                }

                Logger.LogDebug($"Lost an executive (no registration {address})");
            }
            else
            {
                Logger.LogDebug($"Lost an executive (no pool {address})");
            }

            await Task.CompletedTask;
        }
Beispiel #3
0
        public async Task CleanExecutive_Test()
        {
            await _smartContractHelper.CreateChainWithGenesisContractAsync();

            var address = _defaultContractZeroCodeProvider.ContractZeroAddress;

            _smartContractExecutiveProvider.TryGetValue(address, out var pool).ShouldBeTrue();
            pool.Count.ShouldBe(1);
            _smartContractExecutiveService.CleanExecutive(_defaultContractZeroCodeProvider.ContractZeroAddress);
            _smartContractExecutiveProvider.TryGetValue(address, out _).ShouldBeFalse();
        }