Skip to content

Commit 70df9c2

Browse files
committed
implemented test to validate 'createNftType' functionality
Signed-off-by: Manish Dait <[email protected]>
1 parent ccada82 commit 70df9c2

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package com.openelements.hiero.base.test;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.PrivateKey;
5+
import com.hedera.hashgraph.sdk.TokenId;
6+
import com.openelements.hiero.base.HieroException;
7+
import com.openelements.hiero.base.data.Account;
8+
import com.openelements.hiero.base.implementation.NftClientImpl;
9+
import com.openelements.hiero.base.protocol.ProtocolLayerClient;
10+
import com.openelements.hiero.base.protocol.TokenCreateRequest;
11+
import com.openelements.hiero.base.protocol.TokenCreateResult;
12+
import org.junit.jupiter.api.Assertions;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
import org.mockito.ArgumentCaptor;
16+
import org.mockito.Mockito;
17+
18+
import static org.mockito.ArgumentMatchers.any;
19+
import static org.mockito.Mockito.when;
20+
import static org.mockito.Mockito.verify;
21+
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.times;
23+
24+
public class NftClientImplTest {
25+
ProtocolLayerClient protocolLayerClient;
26+
Account operationalAccount;
27+
NftClientImpl nftClientImpl;
28+
29+
ArgumentCaptor<TokenCreateRequest> tokenRequestCaptor = ArgumentCaptor.forClass(TokenCreateRequest.class);
30+
31+
@BeforeEach
32+
public void setup() {
33+
protocolLayerClient = Mockito.mock(ProtocolLayerClient.class);
34+
operationalAccount = Mockito.mock(Account.class);
35+
nftClientImpl = new NftClientImpl(protocolLayerClient, operationalAccount);
36+
}
37+
38+
@Test
39+
void testCreateNftWithNameAndSymbol() throws HieroException {
40+
// mock
41+
final PrivateKey privateKey = PrivateKey.generateECDSA();
42+
final AccountId accountId = AccountId.fromString("1.2.3");
43+
final TokenId tokenId = TokenId.fromString("1.2.3");
44+
final TokenCreateResult tokenCreateResult = mock(TokenCreateResult.class);
45+
46+
// given
47+
final String name = "TOKEN";
48+
final String symbol = "NFT";
49+
50+
// when
51+
when(operationalAccount.privateKey()).thenReturn(privateKey);
52+
when(operationalAccount.accountId()).thenReturn(accountId);
53+
when(protocolLayerClient.executeTokenCreateTransaction(any(TokenCreateRequest.class)))
54+
.thenReturn(tokenCreateResult);
55+
when(tokenCreateResult.tokenId()).thenReturn(tokenId);
56+
57+
final TokenId result = nftClientImpl.createNftType(name, symbol);
58+
59+
// then
60+
// 1st for treasuryKey and 2nd for supplier Key
61+
verify(operationalAccount, times(2)).privateKey();
62+
verify(operationalAccount, times(1)).accountId();
63+
verify(protocolLayerClient, times(1))
64+
.executeTokenCreateTransaction(tokenRequestCaptor.capture());
65+
66+
TokenCreateRequest tokenCreateRequest = tokenRequestCaptor.getValue();
67+
68+
Assertions.assertEquals(privateKey, tokenCreateRequest.treasuryKey());
69+
Assertions.assertEquals(privateKey, tokenCreateRequest.supplyKey());
70+
Assertions.assertEquals(accountId, tokenCreateRequest.treasuryAccountId());
71+
Assertions.assertEquals(name, tokenCreateRequest.name());
72+
Assertions.assertEquals(symbol, tokenCreateRequest.symbol());
73+
Assertions.assertEquals(tokenId, result);
74+
}
75+
76+
@Test
77+
void testCreateNftWithNameSymbolAndSupplier() throws HieroException {
78+
// mock
79+
final PrivateKey privateKey = PrivateKey.generateECDSA();
80+
final AccountId accountId = AccountId.fromString("1.2.3");
81+
final TokenId tokenId = TokenId.fromString("1.2.3");
82+
final TokenCreateResult tokenCreateResult = Mockito.mock(TokenCreateResult.class);
83+
84+
// given
85+
final String name = "TOKEN";
86+
final String symbol = "NFT";
87+
final PrivateKey supplierKey = PrivateKey.generateECDSA();
88+
89+
// when
90+
when(operationalAccount.privateKey()).thenReturn(privateKey);
91+
when(operationalAccount.accountId()).thenReturn(accountId);
92+
when(protocolLayerClient.executeTokenCreateTransaction(any(TokenCreateRequest.class)))
93+
.thenReturn(tokenCreateResult);
94+
when(tokenCreateResult.tokenId()).thenReturn(tokenId);
95+
96+
final TokenId result = nftClientImpl.createNftType(name, symbol, supplierKey);
97+
98+
//then
99+
verify(operationalAccount, times(1)).privateKey();
100+
verify(operationalAccount, times(1)).accountId();
101+
verify(protocolLayerClient, times(1))
102+
.executeTokenCreateTransaction(tokenRequestCaptor.capture());
103+
104+
TokenCreateRequest tokenCreateRequest = tokenRequestCaptor.getValue();
105+
106+
Assertions.assertEquals(privateKey, tokenCreateRequest.treasuryKey());
107+
Assertions.assertEquals(supplierKey, tokenCreateRequest.supplyKey());
108+
Assertions.assertEquals(accountId, tokenCreateRequest.treasuryAccountId());
109+
Assertions.assertEquals(name, tokenCreateRequest.name());
110+
Assertions.assertEquals(symbol, tokenCreateRequest.symbol());
111+
112+
Assertions.assertEquals(tokenId, result);
113+
}
114+
115+
@Test
116+
void testCreateNftWithNameSymbolTreasuryAccountIdAndKey() throws HieroException {
117+
// mock
118+
final PrivateKey privateKey = PrivateKey.generateECDSA();
119+
final TokenId tokenId = TokenId.fromString("1.2.3");
120+
final TokenCreateResult tokenCreateResult = Mockito.mock(TokenCreateResult.class);
121+
122+
// given
123+
final String name = "TOKEN";
124+
final String symbol = "NFT";
125+
final PrivateKey treasuryKey = PrivateKey.generateECDSA();
126+
final AccountId accountId = AccountId.fromString("1.2.3");
127+
128+
// when
129+
when(operationalAccount.privateKey()).thenReturn(privateKey);
130+
when(protocolLayerClient.executeTokenCreateTransaction(any(TokenCreateRequest.class)))
131+
.thenReturn(tokenCreateResult);
132+
when(tokenCreateResult.tokenId()).thenReturn(tokenId);
133+
134+
final TokenId result = nftClientImpl.createNftType(name, symbol, accountId, treasuryKey);
135+
136+
// then
137+
verify(operationalAccount, times(1)).privateKey();
138+
verify(protocolLayerClient, times(1))
139+
.executeTokenCreateTransaction(tokenRequestCaptor.capture());
140+
141+
TokenCreateRequest tokenCreateRequest = tokenRequestCaptor.getValue();
142+
143+
Assertions.assertEquals(treasuryKey, tokenCreateRequest.treasuryKey());
144+
Assertions.assertEquals(privateKey, tokenCreateRequest.supplyKey());
145+
Assertions.assertEquals(accountId, tokenCreateRequest.treasuryAccountId());
146+
Assertions.assertEquals(name, tokenCreateRequest.name());
147+
Assertions.assertEquals(symbol, tokenCreateRequest.symbol());
148+
149+
Assertions.assertEquals(tokenId, result);
150+
}
151+
152+
153+
@Test
154+
void testCreateNftWithAllParam() throws HieroException {
155+
// mock
156+
final TokenId tokenId = TokenId.fromString("1.2.3");
157+
final TokenCreateResult tokenCreateResult = Mockito.mock(TokenCreateResult.class);
158+
159+
// given
160+
final String name = "TOKEN";
161+
final String symbol = "NFT";
162+
final PrivateKey supplierKey = PrivateKey.generateECDSA();
163+
final PrivateKey treasuryKey = PrivateKey.generateECDSA();
164+
final AccountId accountId = AccountId.fromString("1.2.3");
165+
166+
// when
167+
when(protocolLayerClient.executeTokenCreateTransaction(any(TokenCreateRequest.class)))
168+
.thenReturn(tokenCreateResult);
169+
when(tokenCreateResult.tokenId()).thenReturn(tokenId);
170+
171+
final TokenId result = nftClientImpl.createNftType(name, symbol, accountId, treasuryKey, supplierKey);
172+
173+
// then
174+
verify(protocolLayerClient, times(1))
175+
.executeTokenCreateTransaction(tokenRequestCaptor.capture());
176+
177+
TokenCreateRequest tokenCreateRequest = tokenRequestCaptor.getValue();
178+
179+
Assertions.assertEquals(treasuryKey, tokenCreateRequest.treasuryKey());
180+
Assertions.assertEquals(supplierKey, tokenCreateRequest.supplyKey());
181+
Assertions.assertEquals(accountId, tokenCreateRequest.treasuryAccountId());
182+
Assertions.assertEquals(name, tokenCreateRequest.name());
183+
Assertions.assertEquals(symbol, tokenCreateRequest.symbol());
184+
185+
Assertions.assertEquals(tokenId, result);
186+
}
187+
188+
@Test
189+
void testCreateNftForNullParam() {
190+
Assertions.assertThrows(
191+
NullPointerException.class, () -> nftClientImpl.createNftType((String)null, null)
192+
);
193+
Assertions.assertThrows(
194+
NullPointerException.class, () -> nftClientImpl.createNftType(null, null, (PrivateKey) null)
195+
);
196+
Assertions.assertThrows(
197+
NullPointerException.class,
198+
() -> nftClientImpl.createNftType(null, null, (AccountId) null, (PrivateKey) null)
199+
);
200+
Assertions.assertThrows(
201+
NullPointerException.class,
202+
() -> nftClientImpl.createNftType(null, null, null, null, (PrivateKey) null)
203+
);
204+
}
205+
}

hiero-enterprise-spring/src/test/java/com/openelements/hiero/spring/test/NftClientTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.openelements.hiero.spring.test;
22

3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.PrivateKey;
35
import com.hedera.hashgraph.sdk.TokenId;
46
import com.openelements.hiero.base.data.Account;
57
import com.openelements.hiero.base.AccountClient;
@@ -33,6 +35,24 @@ void createNftType() throws Exception {
3335
Assertions.assertNotNull(tokenId);
3436
}
3537

38+
@Test
39+
void testCreateNftForNullParam() {
40+
Assertions.assertThrows(
41+
NullPointerException.class, () -> nftClient.createNftType((String)null, null)
42+
);
43+
Assertions.assertThrows(
44+
NullPointerException.class, () -> nftClient.createNftType(null, null, (PrivateKey) null)
45+
);
46+
Assertions.assertThrows(
47+
NullPointerException.class,
48+
() -> nftClient.createNftType(null, null, (AccountId) null, (PrivateKey) null)
49+
);
50+
Assertions.assertThrows(
51+
NullPointerException.class,
52+
() -> nftClient.createNftType(null, null, null, null, (PrivateKey) null)
53+
);
54+
}
55+
3656
@Test
3757
void mintNft() throws Exception {
3858
//given

0 commit comments

Comments
 (0)