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 async Task <IExecutive> GetExecutiveAsync(IChainContext chainContext, Address address) { if (address == null) { throw new ArgumentNullException(nameof(address)); } var pool = _smartContractExecutiveProvider.GetPool(address); var smartContractRegistration = await GetSmartContractRegistrationAsync(chainContext, address); if (!pool.TryTake(out var executive)) { executive = await GetExecutiveAsync(smartContractRegistration); } else if (smartContractRegistration.CodeHash != executive.ContractHash) { _smartContractExecutiveProvider.TryRemove(address, out _); executive = await GetExecutiveAsync(smartContractRegistration); } return(executive); }