public async Task Pausable_Feature_Test() { EthNetwork.UseDefaultTestNet(); var ownerAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var holderAccount1 = EthAccountFactory.Create(); // Create the ERC20 token... var contract = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(ownerAccount), EthNetwork.Instance.GasPriceProvider); await contract.DeployAsync(); // Perform a transfer and check the result... await contract.TransferAsync(holderAccount1.Address, 2.Algo()); Assert.Equal(2.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); // Pause the contract... await contract.PauseAsync(); // Ensure the contract cannot be used while is in paused state... await Assert.ThrowsAsync <TransactionRejectedException>( () => contract.TransferAsync(holderAccount1.Address, 2.Algo())); // Ensure the balance was not modified... Assert.Equal(2.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); // Unpause the contract... await contract.UnpauseAsync(); // Try a new transfer and ensure it succeeded... await contract.TransferAsync(holderAccount1.Address, 2.Algo()); Assert.Equal(4.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); }
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 ReferralPoolTransferToMinerTest() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var coreTeamAccount = EthAccountFactory.Create(); var minerAccounts = new IAccount[6]; var referralAccounts = new IAccount[6]; await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(coreTeamAccount); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Create a pool... var pool1 = new AlgoPool(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await pool1.DeployAsync(1, token.ContractAddress); // Transfer some tokens to the pool... await token.TransferAsync(pool1.ContractAddress, 100.MAlgo()); // Create miners for each category... AlgoMiner[] miners = new AlgoMiner[6]; for (byte i = 0; i <= 5; i++) { // Create an account for the miner and the referral... minerAccounts[i] = EthAccountFactory.Create(); referralAccounts[i] = EthAccountFactory.Create(); // Create the miner... miners[i] = new AlgoMiner(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await miners[i].DeployAsync(0, i, minerAccounts[i].Address, referralAccounts[i].Address, token.ContractAddress); } // Transfer tokens from the pool to the miners... for (int i = 0; i <= 5; i++) { await pool1.TransferToMinerAsync(miners[i].ContractAddress); } // Ensure each miner received the proper amount of tokens according its category... Assert.Equal(100000.Algo() * 10 / 100, await token.BalanceOfAsync(miners[0].ContractAddress)); Assert.Equal(1.MAlgo() * 10 / 100, await token.BalanceOfAsync(miners[1].ContractAddress)); Assert.Equal(2.MAlgo() * 10 / 100, await token.BalanceOfAsync(miners[2].ContractAddress)); Assert.Equal(3.MAlgo() * 10 / 100, await token.BalanceOfAsync(miners[3].ContractAddress)); Assert.Equal(4.MAlgo() * 10 / 100, await token.BalanceOfAsync(miners[4].ContractAddress)); Assert.Equal(5.MAlgo() * 10 / 100, await token.BalanceOfAsync(miners[5].ContractAddress)); }
private async Task <IAccount> CreateNewAccountAndTransferFromCreatedAccount(IAccount sourceAccount, BigInteger value) { var web3 = new Web3(sourceAccount, EthTestNet.TESTNET_URL); var destinationAccount = EthAccountFactory.Create(); var recepit = await web3.TransactionManager.TransactionReceiptService.SendRequestAndWaitForReceiptAsync(() => web3.TransactionManager.SendTransactionAsync(sourceAccount.Address, destinationAccount.Address, new HexBigInteger(value)) ); return(destinationAccount); }
public async Task Deploy_Contract_And_Transfer_Tokens_Test() { EthNetwork.UseDefaultTestNet(); var ownerAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var holderAccount1 = EthAccountFactory.Create(); // Create the ERC20 token... var contract = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(ownerAccount), EthNetwork.Instance.GasPriceProvider); await contract.DeployAsync(); // Ensure that the initial supply is allocated to the owner... Assert.Equal(INITIAL_SUPPLY.Algo(), await contract.BalanceOfAsync(ownerAccount.Address)); // Perform a transfer... await contract.TransferAsync(holderAccount1.Address, 2.Algo()); // Ensure the receiver got the tokens... Assert.Equal(2.Algo(), await contract.BalanceOfAsync(holderAccount1.Address)); }
public async Task TerminateTest() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var coreTeamAccount = EthAccountFactory.Create(); var minerAccount = EthAccountFactory.Create(); var referralAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(coreTeamAccount); // 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 a miner... var miner1 = new AlgoMiner(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await miner1.DeployAsync(0, 2, minerAccount.Address, referralAccount.Address, token.ContractAddress); // Transfer some tokens to the miner... await token.TransferAsync(miner1.ContractAddress, 100.Algo()); // Ensure the receiver got the tokens... Assert.Equal(100.Algo(), await token.BalanceOfAsync(miner1.ContractAddress)); // Terminate the contract. await miner1.TerminateAsync(); // Ensure the contract returned all the tokens... Assert.Equal(0, await token.BalanceOfAsync(miner1.ContractAddress)); Assert.Equal(100.Algo(), await token.BalanceOfAsync(coreTeamAccount.Address)); }
public Task ExecuteAsync(RuntimeContext context) { string name = string.IsNullOrWhiteSpace(Name) ? string.Format(CultureInfo.InvariantCulture, DEFAULT_NAME_FORMAT, AccountCounter.Next()) : Name; if (context.Accounts.ContainsKey(name)) { throw new Exception($"The name '{name}' already exists."); } var ethAccountDescriptor = new EthAccountDescriptor(name, EthAccountFactory.Create()); context.Accounts.Add(name, ethAccountDescriptor); context.CurrentAccount = ethAccountDescriptor; Console.WriteLine("New account created:"); Console.WriteLine($"- Name: '{name}'."); Console.WriteLine($"- Address: '{ethAccountDescriptor.Account.Address}'."); Console.WriteLine($"- Private Key: '{ethAccountDescriptor.Account.PrivateKey}'."); return(Task.CompletedTask); }
public async Task PublishAndInvokeSmartContract() { var web3 = new Web3(EthTestNet.TESTNET_URL); var account = EthAccountFactory.Create(); await account.RefillAsync(1); web3 = new Web3(account, EthTestNet.TESTNET_URL); var createContractReceipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync( Contracts.Instance.CounterABI, Contracts.Instance.CounterBIN, account.Address, new HexBigInteger(900000)); var contract = web3.Eth.GetContract( Contracts.Instance.CounterABI, createContractReceipt.ContractAddress); var incrementFunction = contract.GetFunction("increment"); var getCountFunction = contract.GetFunction("getCount"); uint counter = 0; var incrementReceipt1 = await incrementFunction.SendTransactionAndWaitForReceiptAsync(account.Address, new HexBigInteger(900000), null); counter = await getCountFunction.CallAsync <uint>(); Assert.Equal((uint)1, counter); var incrementReceipt2 = await incrementFunction.SendTransactionAndWaitForReceiptAsync(account.Address, new HexBigInteger(900000), null); counter = await getCountFunction.CallAsync <uint>(); Assert.Equal((uint)2, counter); }
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)); }
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)); }
public async Task MinerRegistrationTest() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var coreTeamAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(coreTeamAccount); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Create a fees... var fees1 = new AlgoFees(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await fees1.DeployAsync(token.ContractAddress); // Create some miners... var minerAccounts = new IAccount[3]; var referralAccounts = new IAccount[3]; AlgoMiner[] miners = new AlgoMiner[3]; for (int i = 0; i < 3; i++) { // Create an account for the miner and the referral... minerAccounts[i] = EthAccountFactory.Create(); referralAccounts[i] = EthAccountFactory.Create(); // Create the miner... miners[i] = new AlgoMiner(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await miners[i].DeployAsync(0, 2, minerAccounts[i].Address, referralAccounts[i].Address, token.ContractAddress); } // Register a miner... await fees1.RegisterMinerAsync(miners[0].ContractAddress); Assert.Equal(1, await fees1.GetMinerCountAsync()); Assert.Equal(miners[0].ContractAddress, await fees1.GetMinerByIndexAsync(0)); // Remove the only registered miner. await fees1.UnregisterMinerAsync(miners[0].ContractAddress); Assert.Equal(0, await fees1.GetMinerCountAsync()); // Register the 3 miners and ensure they are registered... for (int i = 0; i < 3; i++) { await fees1.RegisterMinerAsync(miners[i].ContractAddress); } Assert.Equal(3, await fees1.GetMinerCountAsync()); for (int i = 0; i < 3; i++) { Assert.Equal(miners[i].ContractAddress, await fees1.GetMinerByIndexAsync(i)); } // Remove the 2nd miner and check... await fees1.UnregisterMinerAsync(miners[1].ContractAddress); Assert.Equal(2, await fees1.GetMinerCountAsync()); Assert.Equal(miners[0].ContractAddress, await fees1.GetMinerByIndexAsync(0)); Assert.Equal(miners[2].ContractAddress, await fees1.GetMinerByIndexAsync(1)); // Add the removed miner back... await fees1.RegisterMinerAsync(miners[1].ContractAddress); Assert.Equal(3, await fees1.GetMinerCountAsync()); Assert.Equal(miners[0].ContractAddress, await fees1.GetMinerByIndexAsync(0)); Assert.Equal(miners[2].ContractAddress, await fees1.GetMinerByIndexAsync(1)); Assert.Equal(miners[1].ContractAddress, await fees1.GetMinerByIndexAsync(2)); // Remove the latest miner... await fees1.UnregisterMinerAsync(miners[1].ContractAddress); Assert.Equal(2, await fees1.GetMinerCountAsync()); Assert.Equal(miners[0].ContractAddress, await fees1.GetMinerByIndexAsync(0)); Assert.Equal(miners[2].ContractAddress, await fees1.GetMinerByIndexAsync(1)); }
public async Task MineTest() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var systemAccount = EthAccountFactory.Create(); var coreTeamAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(systemAccount); await EthNetwork.Instance.RefillAsync(coreTeamAccount); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Create a fees... var fees1 = new AlgoFees(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await fees1.DeployAsync(token.ContractAddress); // Register the system account... await fees1.AddSystemAsync(systemAccount.Address); // Transfer some tokens to the fees... await token.TransferAsync(fees1.ContractAddress, 151.Algo()); // Create one miner per category... var minerAccounts = new IAccount[6]; var referralAccounts = new IAccount[6]; var miners = new AlgoMiner[6]; for (byte i = 0; i <= 5; i++) { // Create an account for the miner and the referral... minerAccounts[i] = EthAccountFactory.Create(); referralAccounts[i] = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(minerAccounts[i]); // Create the miner as "NonPoolBased" so it can be activated... miners[i] = new AlgoMiner(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await miners[i].DeployAsync(1, i, minerAccounts[i].Address, referralAccounts[i].Address, token.ContractAddress); // Activate the miner... await miners[i].ActivateMinerAsync(); // Start mining... { var miner = new AlgoMiner(miners[i].ContractAddress, EthNetwork.Instance.GetWeb3(minerAccounts[i]), EthNetwork.Instance.GasPriceProvider); await miner.StartMiningAsync(); } // Register a miner... await fees1.RegisterMinerAsync(miners[i].ContractAddress); } // Mine the fees... { var fees = new AlgoFees(fees1.ContractAddress, EthNetwork.Instance.GetWeb3(systemAccount), EthNetwork.Instance.GasPriceProvider); await fees.MineAsync(); } // Ensure the miners received the payment from the fees... var balance0 = await token.BalanceOfAsync(minerAccounts[0].Address); var balance1 = await token.BalanceOfAsync(minerAccounts[1].Address); var balance2 = await token.BalanceOfAsync(minerAccounts[2].Address); var balance3 = await token.BalanceOfAsync(minerAccounts[3].Address); var balance4 = await token.BalanceOfAsync(minerAccounts[4].Address); var balance5 = await token.BalanceOfAsync(minerAccounts[5].Address); Assert.Equal(1.Algo(), balance0); Assert.Equal(10.Algo(), balance1); Assert.Equal(20.Algo(), balance2); Assert.Equal(30.Algo(), balance3); Assert.Equal(40.Algo(), balance4); Assert.Equal(50.Algo(), balance5); }
public async Task PoolBasedMinerBasicWorkfloWTest() { EthNetwork.UseDefaultTestNet(); var prefundedAccount = new Account(EthNetwork.Instance.PrefundedPrivateKey); var tokenOwnerAccount = EthAccountFactory.Create(); var systemAccount = EthAccountFactory.Create(); var coreTeamAccount = EthAccountFactory.Create(); var supervisorAccount = EthAccountFactory.Create(); var minerAccount = EthAccountFactory.Create(); var referralAccount = EthAccountFactory.Create(); await EthNetwork.Instance.RefillAsync(tokenOwnerAccount); await EthNetwork.Instance.RefillAsync(systemAccount); await EthNetwork.Instance.RefillAsync(coreTeamAccount); await EthNetwork.Instance.RefillAsync(supervisorAccount); await EthNetwork.Instance.RefillAsync(minerAccount); // Create the ERC20 token... var token = new AlgoTokenV1(EthNetwork.Instance.GetWeb3(tokenOwnerAccount), EthNetwork.Instance.GasPriceProvider); await token.DeployAsync(); // Create the pools to transfer the proper number of tokens to the miners... var pool1 = new AlgoPool(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await pool1.DeployAsync(0, token.ContractAddress); var pool2 = new AlgoPool(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await pool2.DeployAsync(1, token.ContractAddress); // Transfer some tokens to the pools... await token.TransferAsync(pool1.ContractAddress, 100.MAlgo()); await token.TransferAsync(pool2.ContractAddress, 100.MAlgo()); // Create a miner category 2... var miner1 = new AlgoMiner(EthNetwork.Instance.GetWeb3(coreTeamAccount), EthNetwork.Instance.GasPriceProvider); await miner1.DeployAsync(0, 2, minerAccount.Address, referralAccount.Address, token.ContractAddress); // Add roles to the miner... await miner1.AddSystemAsync(systemAccount.Address); await miner1.AddSupervisorAsync(supervisorAccount.Address); // Transfer tokens to the miner... await pool1.TransferToMinerAsync(miner1.ContractAddress); await pool2.TransferToMinerAsync(miner1.ContractAddress); // Ensure the miner received the tokens according to its category 2. Assert.Equal(2.MAlgo() + 2.MAlgo() * 10 / 100, await token.BalanceOfAsync(miner1.ContractAddress)); // Activate the miner... await miner1.ActivateMinerAsync(); // Start mining... miner1.Bind(EthNetwork.Instance.GetWeb3(minerAccount)); await miner1.StartMiningAsync(); // Mine 5 days... miner1.Bind(EthNetwork.Instance.GetWeb3(systemAccount)); var paymentPerDay = 2.MAlgo() / 2 / 365; BigInteger expectedMinerBalance = 0; BigInteger expectedReferralBalance = 0; for (int i = 0; i < 5; i++) { await miner1.MineAsync(); expectedMinerBalance += paymentPerDay; expectedReferralBalance += paymentPerDay * 10 / 100; Assert.Equal(expectedMinerBalance, await token.BalanceOfAsync(minerAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); } // Pause the miner... miner1.Bind(EthNetwork.Instance.GetWeb3(supervisorAccount)); await miner1.PauseMiningAsync(); // Try to mine one day... miner1.Bind(EthNetwork.Instance.GetWeb3(systemAccount)); await Assert.ThrowsAsync <TransactionRejectedException>( () => miner1.MineAsync()); // Ensure the balance is not changed... Assert.Equal(expectedMinerBalance, await token.BalanceOfAsync(minerAccount.Address)); // Resume the miner... miner1.Bind(EthNetwork.Instance.GetWeb3(supervisorAccount)); await miner1.ResumeMiningAsync(); // Mine one day... miner1.Bind(EthNetwork.Instance.GetWeb3(coreTeamAccount)); await miner1.MineAsync(); expectedMinerBalance += paymentPerDay; expectedReferralBalance += paymentPerDay * 10 / 100; Assert.Equal(expectedMinerBalance, await token.BalanceOfAsync(minerAccount.Address)); Assert.Equal(expectedReferralBalance, await token.BalanceOfAsync(referralAccount.Address)); }
public EnrollmentSystemActor() { Account = EthAccountFactory.Create(); _web3 = new Web3(Account, EthTestNet.TESTNET_URL); Account.RefillAsync(1).Wait(); }