private async Task <string> SignAPIAsync() { var lsb = await client.GetLastServiceBlockAsync(); return(Signatures.GetSignature(testPrivateKey, lsb.GetBlock().Hash, testPublicKey)); }
private async Task TestDepositWithdraw(Wallet dexWallet) { //// prepare dex //string lyrawalletfolder = Wallet.GetFullFolderName(networkId, "wallets"); //var walletStore = new SecuredWalletStore(lyrawalletfolder); //var dexWallet = Wallet.Open(walletStore, "dex", ""); //await genesisWallet.SendAsync(100000m, dexWallet.AccountId); //await Task.Delay(1000); //await dexWallet.SyncAsync(genesisWallet.RPC); //Assert.IsTrue(dexWallet.BaseBalance >= 100000m); // external token genesis var lsbret = await client.GetLastServiceBlockAsync(); Assert.IsTrue(lsbret.Successful()); var lsb = lsbret.GetBlock(); var tgexists = await client.GetTokenGenesisBlockAsync(dexWallet.AccountId, "tether/TRX", Signatures.GetSignature(dexWallet.PrivateKey, lsb.Hash, dexWallet.AccountId)); if (!tgexists.Successful()) { var tokenGenesisResult = await dexWallet.CreateTokenAsync("TRX", "tether", "", 8, 0, false, dexWallet.AccountId, "", "", ContractTypes.Cryptocurrency, null); Assert.IsTrue(tokenGenesisResult.Successful(), "dex token genesis failed"); } var dexws = await dexWallet.GetAllDexWalletsAsync(dexWallet.AccountId); Assert.IsNotNull(dexws, "DEX Wallet not setup."); var wcnt = dexws.Count(a => (a as IDexWallet).ExtSymbol == "TRX" && (a as IDexWallet).ExtProvider == "native"); Assert.AreEqual(1, wcnt, $"wallet not created properly. created: {wcnt}"); // must fail await dexWallet.SyncAsync(null); var getokretx = await dexWallet.DexGetTokenAsync((dexws.First() as TransactionBlock).AccountID, 500m); Assert.IsTrue(!getokretx.Successful(), "Should not success"); // mint via dex account /* * var * var dexbrk1 = dexws.First() as TransactionBlock; * var mintRet = await dexWallet.DexMintTokenAsync(dexbrk1.AccountID, 1000m); * Assert.IsTrue(mintRet.Successful(), "Mint failed."); * await Task.Delay(1000); * * var brk1lstret = await client.GetLastBlockAsync(dexbrk1.AccountID); * Assert.IsTrue(brk1lstret.Successful()); * var brk1mint = brk1lstret.GetBlock() as TokenMintBlock; * Assert.IsNotNull(brk1mint); * * if (networkId == "xunit") * { * Assert.AreEqual(2, brk1mint.Height, "No mint block generated."); * Assert.AreEqual(1000, brk1mint.Balances["tether/TRX"].ToBalanceDecimal()); * } * * // get minted token to owner wallet * await dexWallet.SyncAsync(null); * var getokret = await dexWallet.DexGetTokenAsync(dexbrk1.AccountID, 500m); * Assert.IsTrue(getokret.Successful(), "error get ext token to own wallet"); * await Task.Delay(1500); * await dexWallet.SyncAsync(null); * Assert.AreEqual(500m, dexWallet.GetLastSyncBlock().Balances["tether/TRX"].ToBalanceDecimal(), "Ext token amount error"); * * // put external token to dex wallet * var putokret = await dexWallet.DexPutTokenAsync(dexbrk1.AccountID, "tether/TRX", 500m); * Assert.IsTrue(putokret.Successful(), "Put token error"); * await Task.Delay(1500); * var brk1lstret2 = await client.GetLastBlockAsync(dexbrk1.AccountID); * Assert.IsTrue(brk1lstret2.Successful()); * var brk1lastblk = brk1lstret2.GetBlock() as TransactionBlock; * if (networkId == "xunit") * { * Assert.AreEqual(1000m, brk1lastblk.Balances["tether/TRX"].ToBalanceDecimal(), "brk1 ext tok balance error"); * } * * // withdraw token to external blockchain * var wdwret = await dexWallet.DexWithdrawTokenAsync(dexbrk1.AccountID, "Txxxxxxxxx", 1000m); * Assert.IsTrue(wdwret.Successful(), "Error withdraw"); * await Task.Delay(1500); * var brk1lstret3 = await client.GetLastBlockAsync(dexbrk1.AccountID); * Assert.IsTrue(brk1lstret3.Successful()); * var brk1lastblk3 = brk1lstret3.GetBlock() as TokenBurnBlock; * if (networkId == "xunit") * Assert.AreEqual(0m, brk1lastblk3.Balances["tether/TRX"].ToBalanceDecimal(), "brk1 ext tok burn error"); * */ }