static void Main(string[] args) { var ownerAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; var password = "******"; var destinationAddress = "0x6C547791C3573c2093d81b919350DB1094707011"; var web3 = GetWeb3(ownerAddress, password, CONST_ONLINE_TEST_CHAIN_URL); var erc20TokenDeployment = new ERC20TokenDeployment() { DecimalUnits = 18, TokenName = "TST", TokenSymbol = "TST", InitialAmount = Web3.Convert.ToWei(10000) }; //Deploy our custom token var tokenDeploymentReceipt = ERC20TokenService.DeployContractAndWaitForReceiptAsync(web3, erc20TokenDeployment).Result; //Creating a new service var tokenService = new ERC20TokenService(web3, tokenDeploymentReceipt.ContractAddress); //Creating the rules engine, using the default set of rules var wonkaERC20Service = new WonkaERC20Service(ownerAddress, password, tokenDeploymentReceipt.ContractAddress, new StringBuilder(CONST_WONKA_DEFI_RULES), new WonkaDeFiDefaultMetadata(), null, false, CONST_ONLINE_TEST_CHAIN_URL); var RefEnv = WonkaRefEnvironment.GetInstance(); WonkaRefAttr OwnerAddressAttr = RefEnv.GetAttributeByAttrName("OwnerAddress"); WonkaRefAttr VaultAddressAttr = RefEnv.GetAttributeByAttrName("VaultAddress"); WonkaRefAttr TokenTrxAmtAttr = RefEnv.GetAttributeByAttrName("TokenTransferAmt"); WonkaRefAttr VaultYieldRateAttr = RefEnv.GetAttributeByAttrName("VaultYieldRate"); var trxData = new WonkaProduct(); trxData.SetAttribute(OwnerAddressAttr, ownerAddress); trxData.SetAttribute(VaultAddressAttr, destinationAddress); trxData.SetAttribute(TokenTrxAmtAttr, "12"); // Must specify the amount in hex form var currentBalance = tokenService.BalanceOfQueryAsync(ownerAddress).Result; for (int i = 0; (i < 1000) && (currentBalance.CompareTo(0) > 0); ++i) { trxData.SetAttribute(VaultYieldRateAttr, GetCurrentInterestRate()); wonkaERC20Service.Execute(trxData); currentBalance = tokenService.BalanceOfQueryAsync(ownerAddress).Result; var vaultBalance = tokenService.BalanceOfQueryAsync(destinationAddress).Result; Thread.Sleep(5000); } }
public async void ShouldInvokeERC20WonkaService() { var ownerAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; var destinationAddress = "0x6C547791C3573c2093d81b919350DB1094707011"; //Using ropsten infura if wanted for only a tests //var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Ropsten); var web3 = _ethereumClientIntegrationFixture.GetWeb3(); var erc20TokenDeployment = new ERC20TokenDeployment() { DecimalUnits = 18, TokenName = "TST", TokenSymbol = "TST", InitialAmount = Web3.Convert.ToWei(10000) }; //Deploy our custom token var tokenDeploymentReceipt = await ERC20TokenService.DeployContractAndWaitForReceiptAsync(web3, erc20TokenDeployment); //Creating a new service var tokenService = new ERC20TokenService(web3, tokenDeploymentReceipt.ContractAddress); //Creating the rules engine, using the default set of rules var wonkaERC20Service = new WonkaERC20Service("0x12890d2cce102216644c59daE5baed380d84830c", "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7", tokenDeploymentReceipt.ContractAddress); var RefEnv = WonkaRefEnvironment.GetInstance(); WonkaRefAttr OwnerAddressAttr = RefEnv.GetAttributeByAttrName("OwnerAddress"); WonkaRefAttr VaultAddressAttr = RefEnv.GetAttributeByAttrName("VaultAddress"); WonkaRefAttr TokenTrxAmtAttr = RefEnv.GetAttributeByAttrName("TokenTransferAmt"); var trxData = new WonkaProduct(); trxData.SetAttribute(OwnerAddressAttr, ownerAddress); trxData.SetAttribute(VaultAddressAttr, destinationAddress); trxData.SetAttribute(TokenTrxAmtAttr, "12"); // Must specify the amount in hex form var ownerBalance = await tokenService.BalanceOfQueryAsync(ownerAddress); var beforeBalance = await tokenService.BalanceOfQueryAsync(destinationAddress); wonkaERC20Service.Execute(trxData); //validate the current balance (in decimal form) var afterBalance = await tokenService.BalanceOfQueryAsync(destinationAddress); Assert.Equal(18, afterBalance); }