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)); }
public async Task Stream_Ensure_The_Grace_Period_Is_Honored() { 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(); BigInteger expectedHolderBalance; BigInteger expectedReferralBalance; 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(); // 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(); // Ensure the grace period is honored... await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.PauseStreamingAsync()); await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.DisableStreamAsync()); await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.ChangeStreamSizeAsync(2)); await clock.AddDaysAsync(1); // Ensure the grace period is honored... await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.PauseStreamingAsync()); await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.DisableStreamAsync()); await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.ChangeStreamSizeAsync(2)); await clock.AddDaysAsync(1); // Now it should work... await stream.DisableStreamAsync(); }
public async Task Minter_Role_Test() { EthNetwork.UseDefaultTestNet(); var ownerAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var holderAccount1 = EthAccountFactory.Create(); var newMinterAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(newMinterAccount); // Create the ERC20 token... var contract = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(ownerAccount), EthNetwork.Instance.GasPriceProvider); await contract.DeployAsync(); // Check the total supply... Assert.Equal(INITIAL_SUPPLY.Algo(), await contract.TotalSupplyAsync()); // Mint more tokens... await contract.MintAsync(holderAccount1.Address, 100.Algo()); // Check the total supply... Assert.Equal((INITIAL_SUPPLY + 100).Algo(), await contract.TotalSupplyAsync()); // Check balance of the target account... Assert.Equal(100.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); // Add a new minter... await contract.AddMinterAsync(newMinterAccount.Address); // Mint more tokens... contract = new AlgoTokenV1(contract.ContractAddress, EthNetwork.Instance.GetWeb3(newMinterAccount), EthNetwork.Instance.GasPriceProvider); await contract.MintAsync(holderAccount1.Address, 100.Algo()); // Check balance of the target account... Assert.Equal(200.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); }
protected override async Task <TransactionReceipt> ExecuteAsync(RuntimeContext context, string contractAddress, Web3 web3) { var algoToken = new AlgoTokenV1(contractAddress, web3, context.GasPriceProvider); return(await algoToken.AddMinterAsync(context.ResolveAccountOrContractReference(Account))); }
public async Task Stream_Extended_Workflow_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(); BigInteger expectedHolderBalance; BigInteger expectedReferralBalance; 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(); // 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(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 15); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); // Collect the funds... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount)); await clock.AddDaysAsync(15); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 30); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); // Collect the funds... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount)); await clock.AddDaysAsync(100); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 130); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); // Collect the funds... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount)); await clock.AddDaysAsync(400); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 530); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); // Collect the funds... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount)); await clock.AddDaysAsync(3170); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 3700); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); }
public async Task Stream_Disable_And_Reset_Test() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var streamOwnerAccount = EthAccountFactory.Create(); var streamHolderAccount1 = EthAccountFactory.Create(); var referralAccount1 = EthAccountFactory.Create(); var streamHolderAccount2 = EthAccountFactory.Create(); var referralAccount2 = EthAccountFactory.Create(); BigInteger expectedHolderBalance; BigInteger expectedReferralBalance; await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(streamOwnerAccount); await EthNetwork.Instance.RefillAsync(streamHolderAccount1); await EthNetwork.Instance.RefillAsync(streamHolderAccount2); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Create the stream... var stream = new AlgoStream(EthNetwork.Instance.GetWeb3(streamOwnerAccount), EthNetwork.Instance.GasPriceProvider); await stream.DeployAsync(1, 2, streamHolderAccount1.Address, referralAccount1.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(streamHolderAccount1)); await clock.AddDaysAsync(5); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 5); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount1.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount1.Address)); // Disable the stream... stream.Bind(EthNetwork.Instance.GetWeb3(streamOwnerAccount)); await stream.DisableStreamAsync(); // Ensure funds cannot be collected by the holder anymore... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount1)); await clock.AddDaysAsync(5); await Assert.ThrowsAsync <TransactionRejectedException>(() => stream.CollectAsync()); Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount1.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount1.Address)); // Ensure funds cannot be collected even if the owner request it... stream.Bind(EthNetwork.Instance.GetWeb3(streamOwnerAccount)); await stream.CollectAsync(); Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount1.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount1.Address)); // Reset the stream... stream.Bind(EthNetwork.Instance.GetWeb3(streamOwnerAccount)); await stream.ResetStreamAsync(streamHolderAccount2.Address, referralAccount2.Address); // Activate the stream... await stream.ActivateStreamAsync(); // Collect the funds of the new holder... stream.Bind(EthNetwork.Instance.GetWeb3(streamHolderAccount2)); await clock.AddDaysAsync(3); await stream.CollectAsync(); expectedHolderBalance = AlgoStreamFeeAlgorithm.CalculateFees(size: 1, days: 3, startDay: 5); expectedReferralBalance = expectedHolderBalance * 10 / 100; Assert.Equal(expectedHolderBalance, await token.BalanceOfAsync(streamHolderAccount2.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount2.Address)); }