|
| 1 | +package com.openelements.hiero.spring.test; |
| 2 | + |
| 3 | +import com.hedera.hashgraph.sdk.TokenId; |
| 4 | +import com.openelements.hiero.base.data.Account; |
| 5 | +import com.openelements.hiero.base.AccountClient; |
| 6 | +import com.openelements.hiero.base.HieroException; |
| 7 | +import com.openelements.hiero.base.TokenClient; |
| 8 | +import org.junit.jupiter.api.Assertions; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.boot.test.context.SpringBootTest; |
| 12 | + |
| 13 | +@SpringBootTest(classes = TestConfig.class) |
| 14 | +public class TokenClientTest { |
| 15 | + @Autowired |
| 16 | + private TokenClient tokenClient; |
| 17 | + |
| 18 | + @Autowired |
| 19 | + private AccountClient accountClient; |
| 20 | + |
| 21 | + @Test |
| 22 | + void createToken() throws HieroException { |
| 23 | + final String name = "TOKEN"; |
| 24 | + final String symbol = "FT"; |
| 25 | + |
| 26 | + final TokenId tokenId = tokenClient.createToken(name, symbol); |
| 27 | + |
| 28 | + Assertions.assertNotNull(tokenId); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void associateToken() throws HieroException { |
| 33 | + final String name = "TOKEN"; |
| 34 | + final String symbol = "FT"; |
| 35 | + final TokenId tokenId = tokenClient.createToken(name, symbol); |
| 36 | + |
| 37 | + final Account account = accountClient.createAccount(1); |
| 38 | + |
| 39 | + Assertions.assertDoesNotThrow(() -> tokenClient.associateToken(tokenId, account)); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void mintToken() throws HieroException { |
| 44 | + final String name = "TOKEN"; |
| 45 | + final String symbol = "FT"; |
| 46 | + final Long amount = 1L; |
| 47 | + |
| 48 | + final TokenId tokenId = tokenClient.createToken(name, symbol); |
| 49 | + final long totalSupply = tokenClient.mintToken(tokenId, amount); |
| 50 | + |
| 51 | + Assertions.assertEquals(amount, totalSupply); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void burnToken() throws HieroException { |
| 56 | + final String name = "TOKEN"; |
| 57 | + final String symbol = "FT"; |
| 58 | + final long amount = 1L; |
| 59 | + |
| 60 | + final TokenId tokenId = tokenClient.createToken(name, symbol); |
| 61 | + tokenClient.mintToken(tokenId, amount); |
| 62 | + |
| 63 | + final long supplyTotal = tokenClient.burnToken(tokenId, 1L); |
| 64 | + Assertions.assertEquals(0, supplyTotal); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void transferToken() throws HieroException { |
| 69 | + final Account toAccount = accountClient.createAccount(1); |
| 70 | + final String name = "TOKEN"; |
| 71 | + final String symbol = "FT"; |
| 72 | + |
| 73 | + final TokenId tokenId = tokenClient.createToken(name, symbol); |
| 74 | + tokenClient.associateToken(tokenId, toAccount); |
| 75 | + |
| 76 | + long totalSupply = tokenClient.mintToken(tokenId, 1L); |
| 77 | + |
| 78 | + Assertions.assertDoesNotThrow(() -> tokenClient.transferToken(tokenId, toAccount.accountId(), totalSupply)); |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments