-
Notifications
You must be signed in to change notification settings - Fork 16
/
NftTest.java
136 lines (116 loc) · 5.05 KB
/
NftTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package irita.sdk;
import irita.sdk.client.IritaClient;
import irita.sdk.config.ClientConfig;
import irita.sdk.config.OpbConfig;
import irita.sdk.constant.enums.BroadcastMode;
import irita.sdk.key.KeyInfo;
import irita.sdk.key.KeyManager;
import irita.sdk.key.KeyManagerFactory;
import irita.sdk.model.BaseTx;
import irita.sdk.model.Fee;
import irita.sdk.model.ResultTx;
import irita.sdk.module.nft.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import static org.junit.jupiter.api.Assertions.*;
public class NftTest extends ConfigTest {
private KeyManager km;
private NftClient nftClient;
//能量值费用:「创建NFT/MT类别」、「发行NFT/MT」为 40 万能量值(等值人民币:0.1元),其他交易类型为 20 万能量值(等值人民币:0.05元)
private final BaseTx baseTx = new BaseTx(400000, new Fee("400000", "ugas"), BroadcastMode.Commit);
@BeforeEach
public void init() {
IritaClient client = getTestClient();
km = client.getBaseClient().getKm();
nftClient = client.getNftClient();
}
@Test
@Disabled
public void testNft() throws IOException {
String denomID = "denomid" + new Random().nextInt(1000);
String denomName = "test_name" + new Random().nextInt(1000);
String schema = "no shcema";
IssueDenomRequest req = new IssueDenomRequest()
.setId(denomID)
.setName(denomName)
.setSchema(schema)
.setData("data")
.setUri("www.wcchain.com")
.setSymbol("aaa");
ResultTx resultTx = nftClient.issueDenom(req, baseTx);
assertNotNull(resultTx.getResult().getHash());
QueryDenomResp denom = nftClient.queryDenom(denomID);
assertEquals(denomID, denom.getId());
assertEquals(denomName, denom.getName());
assertEquals(schema, denom.getSchema());
KeyInfo keyInfo = km.getCurrentKeyInfo();
assertEquals(keyInfo.getAddress(), denom.getCreator());
String nftID = "nftid08";
String nftName = "你好呀";
String uri = "https://www.baidu.com";
String data = "any data";
MintNFTRequest mintReq = new MintNFTRequest()
.setDenom(denomID)
.setId(nftID)
.setName(nftName)
.setUri(uri)
.setData(data)
.setRecipient(keyInfo.getAddress());
resultTx = nftClient.mintNft(mintReq, baseTx);
assertNotNull(resultTx.getResult().getHash());
String newName = "new_name";
String newUri = "http://xx.com";
String newData = "new_data";
EditNFTRequest editReq = new EditNFTRequest()
.setDenom(denomID)
.setName(newName)
.setId(nftID)
.setUri(newUri)
.setData(newData);
resultTx = nftClient.editNft(editReq, baseTx);
System.out.println(resultTx.getResult().getHash());
assertNotNull(resultTx.getResult().getHash());
QueryNFTResp nft = nftClient.queryNFT(denomID, nftID);
assertEquals(nftID, nft.getId());
assertEquals(newUri, nft.getUri());
assertEquals(newData, nft.getData());
assertEquals(keyInfo.getAddress(), nft.getOwner());
long supply = nftClient.querySupply(denomID, keyInfo.getAddress());
assertEquals(supply, 1);
String reci = "iaa1r49m366kaexmvrlppqqeyr8ykqq248g0d4qra4";
TransferNFTRequest transferReq = new TransferNFTRequest()
.setDenom(denomID)
.setId(nftID)
.setRecipient(reci);
resultTx = nftClient.transferNFt(transferReq, baseTx);
assertNotNull(resultTx.getResult().getHash());
nft = nftClient.queryNFT(denomID, nftID);
assertEquals(reci, nft.getOwner());
List<QueryDenomResp> denoms = nftClient.queryDenoms(null);
assertTrue(denoms.size() > 0);
QueryCollectionResp nfts = nftClient.queryCollection(denomID, null);
assertEquals(denomID, nfts.getDenom().getId());
assertEquals(denomName, nfts.getDenom().getName());
assertEquals(keyInfo.getAddress(), nfts.getDenom().getCreator());
assertTrue(nfts.getNfts().size() > 0);
QueryOwnerResp owner = nftClient.queryOwner(denomID, keyInfo.getAddress(), null);
assertEquals(keyInfo.getAddress(), owner.getAddress());
// BurnNFTRequest burnNFTReq = new BurnNFTRequest()
// .setDenom(denomID)
// .setId(nftID);
// resultTx = nftClient.burnNft(burnNFTReq, baseTx);
// assertNotNull(resultTx.getResult().getHash());
// try {
// nft = nftClient.queryNFT(denomID, nftID);
// } catch (StatusRuntimeException e) {
// if (!e.getMessage().contains("invalid NFT")) {
// throw new IritaSDKException("unknown queryNft error");
// }
// }
}
}