public async Task CanGetTokenReceiptForBurn() { await using var fxToken = await TestToken.CreateAsync(_network); Assert.NotNull(fxToken.Record); Assert.NotNull(fxToken.Record.Token); Assert.True(fxToken.Record.Token.AccountNum > 0); Assert.Equal(ResponseCode.Success, fxToken.Record.Status); var amountToDestory = fxToken.Params.Circulation / 3; var expectedCirculation = fxToken.Params.Circulation - amountToDestory; var originalReceipt = await fxToken.Client.BurnTokenAsync(fxToken, amountToDestory, fxToken.SupplyPrivateKey); Assert.Equal(ResponseCode.Success, originalReceipt.Status); Assert.Equal(expectedCirculation, originalReceipt.Circulation); var copyReceipt = await fxToken.Client.GetReceiptAsync(originalReceipt.Id); var tokenRecipt = Assert.IsType <TokenReceipt>(copyReceipt); Assert.Equal(originalReceipt.Id, tokenRecipt.Id); Assert.Equal(originalReceipt.Status, tokenRecipt.Status); Assert.Equal(originalReceipt.CurrentExchangeRate, tokenRecipt.CurrentExchangeRate); Assert.Equal(originalReceipt.NextExchangeRate, tokenRecipt.NextExchangeRate); Assert.Equal(originalReceipt.Circulation, tokenRecipt.Circulation); }
public async Task CanNotScheduleDissociateTokenFromAccount() { await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxAccount.Client.DissociateTokenAsync( fxToken.Record.Token, fxAccount.Record.Address, new Signatory( fxAccount.PrivateKey, new PendingParams { PendingPayer = fxPayer })); }); Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status); Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message); }
public async Task CanDissociateTokenFromAccountNoExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount); Assert.Equal(fxToken.Record.Token, association.Token); Assert.Equal(fxToken.Params.Symbol, association.Symbol); Assert.Equal(0UL, association.Balance); Assert.Equal(fxToken.Params.Decimals, association.Decimals); Assert.Equal(TokenKycStatus.Revoked, association.KycStatus); Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus); var receipt = await fxAccount.Client.DissociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address, ctx => { ctx.Payer = fxAccount.Record.Address; ctx.Signatory = fxAccount.PrivateKey; }); Assert.Equal(ResponseCode.Success, receipt.Status); await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount); }
public async Task CanDissociateMultipleTokensWithAccountAndGetRecordNoExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxToken1 = await TestToken.CreateAsync(_network, null, fxAccount); await using var fxToken2 = await TestToken.CreateAsync(_network, null, fxAccount); var tokens = new Address[] { fxToken1.Record.Token, fxToken2.Record.Token }; await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount); await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount); var record = await fxAccount.Client.DissociateTokensWithRecordAsync(tokens, fxAccount.Record.Address, ctx => { ctx.Payer = fxAccount.Record.Address; ctx.Signatory = fxAccount.PrivateKey; }); Assert.Equal(ResponseCode.Success, record.Status); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(fxAccount.Record.Address, record.Id.Address); await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount); await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount); }
public async Task DissociationRequiresSigningByTargetAccount() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount); Assert.Equal(fxToken.Record.Token, association.Token); Assert.Equal(fxToken.Params.Symbol, association.Symbol); Assert.Equal(0UL, association.Balance); Assert.Equal(fxToken.Params.Decimals, association.Decimals); Assert.Equal(TokenKycStatus.Revoked, association.KycStatus); Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxAccount.Client.DissociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); Assert.StartsWith("Unable to Dissociate Token from Account, status: InvalidSignature", tex.Message); association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount); Assert.Equal(fxToken.Record.Token, association.Token); Assert.Equal(fxToken.Params.Symbol, association.Symbol); Assert.Equal(0UL, association.Balance); Assert.Equal(fxToken.Params.Decimals, association.Decimals); Assert.Equal(TokenKycStatus.Revoked, association.KycStatus); Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus); }
public async Task AnyAccountWithAdminKeyCanUpdate() { await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxToken = await TestToken.CreateAsync(_network); var newName = Generator.String(30, 50); var updateParams = new UpdateTokenParams { Token = fxToken.Record.Token, Name = newName, Signatory = fxToken.AdminPrivateKey }; var receipt = await fxToken.Client.UpdateTokenAsync(updateParams, ctx => { ctx.Payer = fxAccount.Record.Address; ctx.Signatory = fxAccount.PrivateKey; }); Assert.Equal(ResponseCode.Success, receipt.Status); var info = await fxToken.Client.GetTokenInfoAsync(fxToken.Record.Token); Assert.Equal(newName, info.Name); }
public async Task CanUpdateTreasuryToContract() { await using var fxContract = await GreetingContract.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network); // Note: Contract did not need to sign. await fxContract.Client.AssociateTokenAsync(fxToken, fxContract, fxContract.PrivateKey); var updateParams = new UpdateTokenParams { Token = fxToken.Record.Token, Treasury = fxContract.ContractRecord.Contract, Signatory = new Signatory(fxToken.AdminPrivateKey, fxContract.PrivateKey) }; var receipt = await fxToken.Client.UpdateTokenAsync(updateParams); Assert.Equal(ResponseCode.Success, receipt.Status); var info = await fxToken.Client.GetTokenInfoAsync(fxToken.Record.Token); Assert.Equal(fxContract.ContractRecord.Contract, info.Treasury); Assert.Equal(fxToken.Params.Circulation, await fxToken.Client.GetContractTokenBalanceAsync(fxContract, fxToken)); }
public async Task CanReumeTokenCoinTradingAndGetRecordNoExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.InitializeSuspended = true; }, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Suspended); var record = await fxToken.Client.ResumeTokenWithRecordAsync(fxToken.Record.Token, fxAccount, ctx => ctx.Signatory = new Signatory(_network.Signatory, fxToken.SuspendPrivateKey)); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(_network.Payer, record.Id.Address); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); }
public async Task CanRevokeTokenCoinsFromAnyAccountWithGrantKey() { await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); await fxToken.Client.GrantTokenKycAsync(fxToken, fxAccount, fxToken.GrantPrivateKey); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await fxToken.Client.RevokeTokenKycAsync(fxToken.Record.Token, fxAccount, fxToken.GrantPrivateKey, ctx => { ctx.Payer = fxOther.Record.Address; ctx.Signatory = fxOther.PrivateKey; }); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); }); Assert.Equal(ResponseCode.AccountKycNotGrantedForToken, tex.Status); Assert.StartsWith("Unable to execute transfers, status: AccountKycNotGrantedForToken", tex.Message); }
public async Task CanResumeASuspendedAccount() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.InitializeSuspended = false; }, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); await fxToken.Client.SuspendTokenAsync(fxToken.Record.Token, fxAccount, fxToken.SuspendPrivateKey); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Suspended); await fxToken.Client.ResumeTokenAsync(fxToken.Record.Token, fxAccount, fxToken.SuspendPrivateKey); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); }
public async Task CanNotResumeTokenWhenFreezeNotEnabled() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.SuspendEndorsement = null; fx.Params.InitializeSuspended = false; }, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.NotApplicable); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.ResumeTokenAsync(fxToken.Record.Token, fxAccount, fxToken.SuspendPrivateKey); }); Assert.Equal(ResponseCode.TokenHasNoFreezeKey, tex.Status); Assert.StartsWith("Unable to Resume Token, status: TokenHasNoFreezeKey", tex.Message); var info = (await fxAccount.Client.GetAccountInfoAsync(fxAccount)).Tokens.FirstOrDefault(t => t.Token == fxToken.Record.Token); Assert.Equal(0Ul, info.Balance); Assert.Equal(TokenTradableStatus.NotApplicable, info.TradableStatus); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.NotApplicable); }
public async Task ResumingAnUnfrozenAccountIsNoop() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.InitializeSuspended = false; }, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); await fxToken.Client.ResumeTokenAsync(fxToken.Record.Token, fxAccount, fxToken.SuspendPrivateKey); var info = (await fxAccount.Client.GetAccountInfoAsync(fxAccount)).Tokens.FirstOrDefault(t => t.Token == fxToken.Record.Token); Assert.Equal(0Ul, info.Balance); Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); info = (await fxAccount.Client.GetAccountInfoAsync(fxAccount)).Tokens.FirstOrDefault(t => t.Token == fxToken.Record.Token); Assert.Equal(xferAmount, info.Balance); Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus); }
public async Task CanReumeTokenCoinTradingFromAnyAccountWithSuspendKey() { await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 100_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.InitializeSuspended = true; }, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Suspended); await fxToken.Client.ResumeTokenAsync(fxToken.Record.Token, fxAccount, fxToken.SuspendPrivateKey, ctx => { ctx.Payer = fxOther.Record.Address; ctx.Signatory = fxOther.PrivateKey; }); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenTradableStatus.Tradable); }
public void TokenSignAndVerify() { var token = new TestToken() { Header = new DefaultJwtHeader() { Algorithm = SecurityAlgorithms.HmacSha256 }, Payload = new CommonPayload() { Actor = "TestUser", Audience = "TestAudience", Issuer = "TestIssuer", Subject = "TestTokens", IssuedAt = DateTime.Now, Expires = DateTime.Now } }; var testKey = new SymmetricSecurityKey("TestKey".ToHash <MD5>()); var tokenString = token.Sign(testKey); var isVaild = JwtTokenConvert.Verify <CommonPayload>( tokenString, testKey, out var verifyToken); Assert.True(isVaild); Assert.Equal(JObject.FromObject(token), JObject.FromObject(verifyToken)); }
public async Task CanGetTokenReceiptForConfiscate() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var xferAmount = 2 * fxToken.Params.Circulation / (ulong)Generator.Integer(3, 5); var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var originalReceipt = await fxToken.Client.ConfiscateTokensAsync(fxToken, fxAccount, xferAmount, fxToken.ConfiscatePrivateKey); Assert.Equal(ResponseCode.Success, originalReceipt.Status); Assert.Equal(expectedTreasury, originalReceipt.Circulation); var copyReceipt = await fxToken.Client.GetReceiptAsync(originalReceipt.Id); var tokenReceipt = Assert.IsType <TokenReceipt>(copyReceipt); Assert.Equal(originalReceipt.Id, tokenReceipt.Id); Assert.Equal(originalReceipt.Status, tokenReceipt.Status); Assert.Equal(originalReceipt.CurrentExchangeRate, tokenReceipt.CurrentExchangeRate); Assert.Equal(originalReceipt.NextExchangeRate, tokenReceipt.NextExchangeRate); Assert.Equal(originalReceipt.Circulation, tokenReceipt.Circulation); }
public async Task RevokeTokenCoinsRequiresGrantKeySignature() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); await fxToken.Client.GrantTokenKycAsync(fxToken, fxAccount, fxToken.GrantPrivateKey); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.RevokeTokenKycAsync(fxToken.Record.Token, fxAccount); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); Assert.StartsWith("Unable to Revoke Token, status: InvalidSignature", tex.Message); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); }
public async Task CanNotScheduleUpdateToken() { await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000); await using var fxToken = await TestToken.CreateAsync(_network); var newSymbol = Generator.UppercaseAlphaCode(20); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.UpdateTokenAsync(new UpdateTokenParams { Token = fxToken.Record.Token, Symbol = newSymbol, Signatory = new Signatory( fxToken.AdminPrivateKey, new PendingParams { PendingPayer = fxPayer }) }); }); Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status); Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message); }
public async Task CanDissociateMultipleTokensWithAccountNoExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxToken1 = await TestToken.CreateAsync(_network, null, fxAccount); await using var fxToken2 = await TestToken.CreateAsync(_network, null, fxAccount); var tokens = new Address[] { fxToken1.Record.Token, fxToken2.Record.Token }; await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount); await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount); var receipt = await fxAccount.Client.DissociateTokensAsync(tokens, fxAccount.Record.Address, ctx => { ctx.Payer = fxAccount.Record.Address; ctx.Signatory = fxAccount.PrivateKey; }); Assert.Equal(ResponseCode.Success, receipt.Status); await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount); await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount); }
public async Task UpdatingToUsedNameIsAllowed() { await using var fxToken = await TestToken.CreateAsync(_network); await using var fxOther = await TestToken.CreateAsync(_network); var updateParams = new UpdateTokenParams { Token = fxToken.Record.Token, Name = fxOther.Params.Name, Signatory = fxToken.AdminPrivateKey }; await fxToken.Client.UpdateTokenAsync(updateParams); var info = await fxToken.Client.GetTokenInfoAsync(fxToken.Record.Token); Assert.Equal(fxToken.Record.Token, info.Token); Assert.Equal(fxToken.Params.Symbol, info.Symbol); Assert.Equal(fxOther.Params.Name, info.Name); Assert.Equal(fxToken.TreasuryAccount.Record.Address, info.Treasury); Assert.Equal(fxToken.Params.Circulation, info.Circulation); Assert.Equal(fxToken.Params.Decimals, info.Decimals); Assert.Equal(fxToken.Params.Administrator, info.Administrator); Assert.Equal(fxToken.Params.GrantKycEndorsement, info.GrantKycEndorsement); Assert.Equal(fxToken.Params.SuspendEndorsement, info.SuspendEndorsement); Assert.Equal(fxToken.Params.ConfiscateEndorsement, info.ConfiscateEndorsement); Assert.Equal(fxToken.Params.SupplyEndorsement, info.SupplyEndorsement); Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus); Assert.Equal(TokenKycStatus.Revoked, info.KycStatus); Assert.False(info.Deleted); Assert.Equal(fxToken.Params.Memo, info.Memo); }
public async Task RemovingAnAutoRenewAccountIsNotAllowed() { await using var fxToken = await TestToken.CreateAsync(_network); var receipt = await fxToken.Client.DeleteAccountAsync(fxToken.RenewAccount, _network.Payer, fxToken.RenewAccount); Assert.Equal(ResponseCode.Success, receipt.Status); var info = await fxToken.Client.GetTokenInfoAsync(fxToken); Assert.Equal(fxToken.Record.Token, info.Token); Assert.Equal(fxToken.Params.Symbol, info.Symbol); Assert.Equal(fxToken.TreasuryAccount.Record.Address, info.Treasury); Assert.Equal(fxToken.Params.Circulation, info.Circulation); Assert.Equal(fxToken.Params.Decimals, info.Decimals); Assert.Equal(fxToken.Params.Administrator, info.Administrator); Assert.Equal(fxToken.Params.GrantKycEndorsement, info.GrantKycEndorsement); Assert.Equal(fxToken.Params.SuspendEndorsement, info.SuspendEndorsement); Assert.Equal(fxToken.Params.ConfiscateEndorsement, info.ConfiscateEndorsement); Assert.Equal(fxToken.Params.SupplyEndorsement, info.SupplyEndorsement); Assert.Equal(fxToken.Params.RenewAccount, info.RenewAccount); Assert.Equal(fxToken.Params.RenewPeriod, info.RenewPeriod); Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus); Assert.Equal(TokenKycStatus.Revoked, info.KycStatus); Assert.False(info.Deleted); Assert.Equal(fxToken.Params.Memo, info.Memo); }
public async Task CanChangeTreasuryToUnassociatedAccount() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.ConfiscateEndorsement = null; fx.Params.SuspendEndorsement = null; fx.Params.GrantKycEndorsement = null; }); var totalCirculation = fxToken.Params.Circulation; Assert.Equal(0UL, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(totalCirculation, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); // Returns A Failure var tex = await Assert.ThrowsAnyAsync <TransactionException>(async() => { await fxToken.Client.UpdateTokenAsync(new UpdateTokenParams { Token = fxToken.Record.Token, Treasury = fxAccount.Record.Address, Signatory = new Signatory(fxToken.AdminPrivateKey, fxAccount.PrivateKey) }); }); Assert.Equal(ResponseCode.InvalidTreasuryAccountForToken, tex.Status); // Confirm it did not change the Treasury Account var info = await fxToken.Client.GetTokenInfoAsync(fxToken); Assert.Equal(fxToken.TreasuryAccount.Record.Address, info.Treasury); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testC() throws java.io.IOException public virtual void testC() { string str = "abc defgh ijklmn opqrstu vwxy z"; TestToken[] out_tokens = new TestToken[] {newToken("abc", 0, 3, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("defgh", 4, 9, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("ijklmn", 10, 16, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("opqrstu", 17, 24, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("vwxy", 25, 29, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("z", 30, 31, CJKTokenizer.SINGLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
public async Task CanAssociateTokenWithAccountAndGetRecordNoExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxToken = await TestToken.CreateAsync(_network); await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount); var record = await fxAccount.Client.AssociateTokenWithRecordAsync(fxToken.Record.Token, fxAccount.Record.Address, ctx => { ctx.Payer = fxAccount.Record.Address; ctx.Signatory = fxAccount.PrivateKey; }); Assert.Equal(ResponseCode.Success, record.Status); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(fxAccount.Record.Address, record.Id.Address); var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount); Assert.Equal(fxToken.Record.Token, association.Token); Assert.Equal(fxToken.Params.Symbol, association.Symbol); Assert.Equal(0UL, association.Balance); Assert.Equal(fxToken.Params.Decimals, association.Decimals); Assert.Equal(TokenKycStatus.Revoked, association.KycStatus); Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus); }
public void EvaluateNodeWritesToTopFrameStack() { // Create context var context = CreateContext(); var symbol = SymbolTable.Symbols.TextToSymbol("id"); // Insert value in lower frame context.SetLocalValue(symbol, 24); context.PushFrame("x", null, context.CurrentFrame); // Insert value in top frame context.SetLocalValue(symbol, 42); context.PushFrame("y", null, context.CurrentFrame); context.Data.Push(100); // Try evaluating var sut = new LocalIdentifierNode(); var token = new TestToken(symbol); sut.Init(null, new ParseTreeNode(token)); sut.EvaluateNode(context, AstMode.Write); var actual = context.CurrentFrame.Values[symbol]; Assert.That(actual, Is.EqualTo(100)); // Check that parent value is untouched. This is what differentiate LocalIdentifierNode from IdentifierNode Assert.That(context.CurrentFrame.Parent.Values[symbol], Is.EqualTo(42)); }
public async Task CanNotScheduleGrantTokenCoins() { await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.GrantTokenKycAsync( fxToken.Record.Token, fxAccount, new Signatory( fxToken.GrantPrivateKey, new PendingParams { PendingPayer = fxPayer })); }); Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status); Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message); }
public async Task CanGrantTokenCoinsFromWnyAccountWithGrantKey() { await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); await fxToken.Client.GrantTokenKycAsync(fxToken.Record.Token, fxAccount, fxToken.GrantPrivateKey, ctx => { ctx.Payer = fxOther.Record.Address; ctx.Signatory = fxOther.PrivateKey; }); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); }
public async Task CannotConfiscateWhenNoConfiscationEndorsement() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => { fx.Params.GrantKycEndorsement = null; fx.Params.ConfiscateEndorsement = null; }, fxAccount); var xferAmount = 2ul; var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.ConfiscateTokensAsync(fxToken, fxAccount, xferAmount, fxToken.ConfiscatePrivateKey); }); Assert.Equal(ResponseCode.TokenHasNoWipeKey, tex.Status); Assert.StartsWith("Unable to Confiscate Token, status: TokenHasNoWipeKey", tex.Message); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); }
public async Task CanConfiscateASmallAmountTokenCoinsAndGetRecord() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var xferAmount = 2ul; var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var record = await fxToken.Client.ConfiscateTokensWithRecordAsync(fxToken, fxAccount, xferAmount, fxToken.ConfiscatePrivateKey); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(_network.Payer, record.Id.Address); Assert.Equal(expectedTreasury, record.Circulation); Assert.Equal(0ul, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(expectedTreasury, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); }
public async Task ConfiscationRequiresConfiscateKeySignature() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var xferAmount = 2ul; var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fxToken.Client.ConfiscateTokensAsync(fxToken, fxAccount, xferAmount); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); Assert.StartsWith("Unable to Confiscate Token, status: InvalidSignature", tex.Message); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); }
public async Task ConfiscateRecordIncludesTokenTransfers() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var xferAmount = 2ul; var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var record = await fxToken.Client.ConfiscateTokensWithRecordAsync(fxToken, fxAccount, xferAmount, fxToken.ConfiscatePrivateKey); Assert.Equal(ResponseCode.Success, record.Status); Assert.Equal(expectedTreasury, record.Circulation); Assert.Single(record.TokenTransfers); var xfer = record.TokenTransfers[0]; Assert.Equal(fxToken.Record.Token, xfer.Token); Assert.Equal(fxAccount.Record.Address, xfer.Address); Assert.Equal(-(long)xferAmount, xfer.Amount); Assert.Equal(fxToken.Params.Circulation - xferAmount, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); }
public async Task CanConfiscateASmallAmountTokenCoinsFromAnyAccountWithConfiscateKey() { await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000); await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var xferAmount = 2ul; var expectedTreasury = fxToken.Params.Circulation - xferAmount; await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); Assert.Equal(xferAmount, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(fxToken.Params.Circulation, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); var receipt = await fxToken.Client.ConfiscateTokensAsync(fxToken, fxAccount, xferAmount, fxToken.ConfiscatePrivateKey, ctx => { ctx.Payer = fxOther.Record.Address; ctx.Signatory = fxOther.PrivateKey; }); Assert.Equal(ResponseCode.Success, receipt.Status); Assert.Equal(expectedTreasury, receipt.Circulation); Assert.Equal(0ul, await fxAccount.Client.GetAccountTokenBalanceAsync(fxAccount, fxToken)); Assert.Equal(expectedTreasury, await fxAccount.Client.GetAccountTokenBalanceAsync(fxToken.TreasuryAccount, fxToken)); Assert.Equal(expectedTreasury, (await fxToken.Client.GetTokenInfoAsync(fxToken)).Circulation); }
public async Task CanGrantTokensAndGetRecordWithoutExtraSignatory() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount); var circulation = fxToken.Params.Circulation; var xferAmount = circulation / 3; await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Revoked); var record = await fxToken.Client.GrantTokenKycWithRecordAsync(fxToken.Record.Token, fxAccount, ctx => ctx.Signatory = new Signatory(_network.Signatory, fxToken.GrantPrivateKey)); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(_network.Payer, record.Id.Address); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount); await AssertHg.TokenStatusAsync(fxToken, fxAccount, TokenKycStatus.Granted); }
public virtual TestToken newToken(string termText, int start, int end, int type) { TestToken token = new TestToken(this); token.termText = termText; token.type = CJKTokenizer.TOKEN_TYPE_NAMES[type]; token.start = start; token.end = end; return token; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void checkCJKTokenReusable(final org.apache.lucene.analysis.Analyzer a, final String str, final TestToken[] out_tokens) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual void checkCJKTokenReusable(Analyzer a, string str, TestToken[] out_tokens) { Analyzer analyzer = new CJKAnalyzer(Version.LUCENE_30); string[] terms = new string[out_tokens.Length]; int[] startOffsets = new int[out_tokens.Length]; int[] endOffsets = new int[out_tokens.Length]; string[] types = new string[out_tokens.Length]; for (int i = 0; i < out_tokens.Length; i++) { terms[i] = out_tokens[i].termText; startOffsets[i] = out_tokens[i].start; endOffsets[i] = out_tokens[i].end; types[i] = out_tokens[i].type; } assertAnalyzesTo(analyzer, str, terms, startOffsets, endOffsets, types, null); }
public void EvaluateNodeReadsFromTopMostSymbolInFrameStack() { // Create context var context = CreateContext(); var symbol = SymbolTable.Symbols.TextToSymbol("id"); // Insert value in lower frame context.SetLocalValue(symbol, 24); context.PushFrame("x", null, context.CurrentFrame); // Insert value in top frame context.SetLocalValue(symbol, 42); context.PushFrame("y", null, context.CurrentFrame); // Try evaluating var sut = new IdentifierNode(); var token = new TestToken(symbol); sut.Init(null, new ParseTreeNode(token)); sut.EvaluateNode(context, AstMode.Read); var actual = context.LastResult; Assert.That(actual, Is.EqualTo(42)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testJa2() throws java.io.IOException public virtual void testJa2() { string str = "\u4e00 \u4e8c\u4e09\u56db \u4e94\u516d\u4e03\u516b\u4e5d \u5341"; TestToken[] out_tokens = new TestToken[] {newToken("\u4e00", 0, 1, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u4e8c\u4e09", 2, 4, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u4e09\u56db", 3, 5, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u4e94\u516d", 6, 8, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u516d\u4e03", 7, 9, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u4e03\u516b", 8, 10, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u516b\u4e5d", 9, 11, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u5341", 12,13, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
/* * Full-width text is normalized to half-width */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testFullWidth() throws Exception public virtual void testFullWidth() { string str = "Test 1234"; TestToken[] out_tokens = new TestToken[] {newToken("test", 0, 4, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("1234", 5, 9, CJKTokenizer.SINGLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testReusableTokenStream() throws Exception public virtual void testReusableTokenStream() { Analyzer analyzer = new CJKAnalyzer(Version.LUCENE_30); string str = "\u3042\u3044\u3046\u3048\u304aabc\u304b\u304d\u304f\u3051\u3053"; TestToken[] out_tokens = new TestToken[] {newToken("\u3042\u3044", 0, 2, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3044\u3046", 1, 3, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3046\u3048", 2, 4, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3048\u304a", 3, 5, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("abc", 5, 8, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("\u304b\u304d", 8, 10, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304d\u304f", 9, 11, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304f\u3051", 10,12, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3051\u3053", 11,13, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKTokenReusable(analyzer, str, out_tokens); str = "\u3042\u3044\u3046\u3048\u304aab\u3093c\u304b\u304d\u304f\u3051 \u3053"; TestToken[] out_tokens2 = new TestToken[] {newToken("\u3042\u3044", 0, 2, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3044\u3046", 1, 3, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3046\u3048", 2, 4, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3048\u304a", 3, 5, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("ab", 5, 7, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("\u3093", 7, 8, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("c", 8, 9, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("\u304b\u304d", 9, 11, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304d\u304f", 10, 12, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304f\u3051", 11,13, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3053", 14,15, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKTokenReusable(analyzer, str, out_tokens2); }
/* * Non-english text with nonletters (non-spacing marks,etc) is treated as C1C2 C2C3, * except for words are split around non-letters. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testNonIdeographicNonLetter() throws Exception public virtual void testNonIdeographicNonLetter() { string str = "\u4e00 رُوبرت موير"; TestToken[] out_tokens = new TestToken[] {newToken("\u4e00", 0, 1, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("ر", 2, 3, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("وب", 4, 6, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("بر", 5, 7, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("رت", 6, 8, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("مو", 9, 11, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("وي", 10, 12, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("ير", 11, 13, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testSingleChar() throws java.io.IOException public virtual void testSingleChar() { string str = "\u4e00"; TestToken[] out_tokens = new TestToken[] {newToken("\u4e00", 0, 1, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testMix2() throws java.io.IOException public virtual void testMix2() { string str = "\u3042\u3044\u3046\u3048\u304aab\u3093c\u304b\u304d\u304f\u3051 \u3053"; TestToken[] out_tokens = new TestToken[] {newToken("\u3042\u3044", 0, 2, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3044\u3046", 1, 3, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3046\u3048", 2, 4, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3048\u304a", 3, 5, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("ab", 5, 7, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("\u3093", 7, 8, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("c", 8, 9, CJKTokenizer.SINGLE_TOKEN_TYPE), newToken("\u304b\u304d", 9, 11, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304d\u304f", 10, 12, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u304f\u3051", 11,13, CJKTokenizer.DOUBLE_TOKEN_TYPE), newToken("\u3053", 14,15, CJKTokenizer.DOUBLE_TOKEN_TYPE)}; checkCJKToken(str, out_tokens); }
private void InitBlock() { positions = new int[testTerms.Length][]; offsets = new TermVectorOffsetInfo[testTerms.Length][]; tokens = new TestToken[testTerms.Length * TERM_FREQ]; }
public override void SetUp() { base.SetUp(); /* for (int i = 0; i < testFields.length; i++) { fieldInfos.add(testFields[i], true, true, testFieldsStorePos[i], testFieldsStoreOff[i]); } */ System.Array.Sort(testTerms); int tokenUpto = 0; for (int i = 0; i < testTerms.Length; i++) { positions[i] = new int[TERM_FREQ]; offsets[i] = new TermVectorOffsetInfo[TERM_FREQ]; // first position must be 0 for (int j = 0; j < TERM_FREQ; j++) { // positions are always sorted in increasing order positions[i][j] = (int) (j * 10 + (new System.Random().NextDouble()) * 10); // offsets are always sorted in increasing order offsets[i][j] = new TermVectorOffsetInfo(j * 10, j * 10 + testTerms[i].Length); TestToken token = tokens[tokenUpto++] = new TestToken(this); token.text = testTerms[i]; token.pos = positions[i][j]; token.startOffset = offsets[i][j].GetStartOffset(); token.endOffset = offsets[i][j].GetEndOffset(); } } System.Array.Sort(tokens); IndexWriter writer = new IndexWriter(dir, new MyAnalyzer(this), true, IndexWriter.MaxFieldLength.LIMITED); writer.SetUseCompoundFile(false); Document doc = new Document(); for (int i = 0; i < testFields.Length; i++) { Field.TermVector tv; if (testFieldsStorePos[i] && testFieldsStoreOff[i]) tv = Field.TermVector.WITH_POSITIONS_OFFSETS; else if (testFieldsStorePos[i] && !testFieldsStoreOff[i]) tv = Field.TermVector.WITH_POSITIONS; else if (!testFieldsStorePos[i] && testFieldsStoreOff[i]) tv = Field.TermVector.WITH_OFFSETS; else tv = Field.TermVector.YES; doc.Add(new Field(testFields[i], "", Field.Store.NO, Field.Index.ANALYZED, tv)); } //Create 5 documents for testing, they all have the same //terms for (int j = 0; j < 5; j++) writer.AddDocument(doc); writer.Flush(); seg = writer.NewestSegment().name; writer.Close(); fieldInfos = new FieldInfos(dir, seg + "." + IndexFileNames.FIELD_INFOS_EXTENSION); }
public TestToken(TestToken t1, TestToken t2, TestToken t3) {}