public async Task Stream_Terminate_Test() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var streamOwnerAccount = EthAccountFactory.Create(); var streamHolderAccount = EthAccountFactory.Create(); var referralAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(streamOwnerAccount); await EthNetwork.Instance.RefillAsync(streamHolderAccount); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Store the current balance of the token owner... var tokenOwnerAccountBalance = await token.BalanceOfAsync(tokenOwnerAccount.Address); // Create the stream... var stream = new AlgoStream(EthNetwork.Instance.GetWeb3(streamOwnerAccount), EthNetwork.Instance.GasPriceProvider); await stream.DeployAsync(1, 2, streamHolderAccount.Address, referralAccount.Address, token.ContractAddress); // Add the stream as minter... await token.AddMinterAsync(stream.ContractAddress); // Setup the clock... var clock = await Clock.FromAsync(2019, 3, 1, 15, 30, x => stream.SetCurrentDateTimeAsync(x)); // Activate the stream... await stream.ActivateStreamAsync(); // Collect the funds... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount)); await clock.AddDaysAsync(15); await stream.CollectAsync(); // Transfer some tokens to the stream... await token.TransferAsync(stream.ContractAddress, 100.Algo()); // Ensure the stream got the tokens... Assert.Equal(100.Algo(), await token.BalanceOfAsync(stream.ContractAddress)); // Terminate the stream... stream.Bind(EthNetwork.Instance.GetWeb3(streamOwnerAccount)); await stream.TerminateAsync(); // Ensure the stream returned all the tokens... Assert.Equal(0, await token.BalanceOfAsync(stream.ContractAddress)); Assert.Equal(tokenOwnerAccountBalance - 100.Algo(), await token.BalanceOfAsync(tokenOwnerAccount.Address)); // Ensure the stream is not a minter anymore... Assert.False(await token.IsMinterAsync(stream.ContractAddress)); }
protected override async Task <object> ExecuteAsync(RuntimeContext context, string contractAddress, Web3 web3) { var algoToken = new AlgoTokenV1(contractAddress, web3, context.GasPriceProvider); return(await algoToken.IsMinterAsync(context.ResolveAccountOrContractReference(Account))); }