Skip to content

Commit

Permalink
fix functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex v committed Dec 9, 2024
1 parent 3df89da commit 85b04a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
45 changes: 29 additions & 16 deletions src/blsct/tokens/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,52 @@
#include <util/strencodings.h>
#include <validation.h>

std::vector<RPCResult> tokenInfoResult = {
RPCResult{RPCResult::Type::STR_HEX, "tokenId", "the token id"},
RPCResult{RPCResult::Type::STR_HEX, "publicKey", "the token public key"},
RPCResult{RPCResult::Type::STR, "type", "the token type"},
RPCResult{RPCResult::Type::OBJ_DYN, "metadata", "the token metadata", {
{RPCResult::Type::STR, "<key>", "the metadata value"},
}},
RPCResult{RPCResult::Type::NUM, "maxSupply", "the token max supply"}, RPCResult{RPCResult::Type::NUM, "currentSupply", true, "the token current supply"}, RPCResult{RPCResult::Type::OBJ_DYN, "mintedNft", true, "the nfts already minted", {{RPCResult::Type::OBJ, "<nft_index>", "", {
{RPCResult::Type::STR, "<metadata_key>", "the metadata value"},
}}}}
std::vector<RPCResult> metadataResult = {
{RPCResult::Type::OBJ, "metadata", "", {
{RPCResult::Type::STR, "key", "the metadata key"},
{RPCResult::Type::STR, "value", "the metadata value"},
}}};

std::vector<RPCResult>
tokenInfoResult = {
RPCResult{RPCResult::Type::STR_HEX, "tokenId", "the token id"}, RPCResult{RPCResult::Type::STR_HEX, "publicKey", "the token public key"},
RPCResult{RPCResult::Type::STR, "type", "the token type"},
RPCResult{RPCResult::Type::ARR, "metadata", "the token metadata", metadataResult},
RPCResult{RPCResult::Type::NUM, "maxSupply", "the token max supply"},
RPCResult{RPCResult::Type::NUM, "currentSupply", true, "the token current supply"},
RPCResult{RPCResult::Type::ARR, "mintedNft", true, "the nfts already minted", {{RPCResult::Type::OBJ, "", "", {{RPCResult::Type::STR, "index", "the nft index"}, {RPCResult::Type::ARR, "metadata", "the token metadata", metadataResult}}}}}

};

void TokenToUniValue(UniValue& obj, const blsct::TokenEntry& token)
{
obj.pushKV("publicKey", token.info.publicKey.ToString());
obj.pushKV("type", blsct::TokenTypeToString(token.info.type));
UniValue metadata{UniValue::VOBJ};
UniValue metadata{UniValue::VARR};
for (auto& it : token.info.mapMetadata) {
metadata.pushKV(it.first, it.second);
UniValue metadataObj{UniValue::VOBJ};
metadataObj.pushKV("key", it.first);
metadataObj.pushKV("value", it.second);
metadata.push_back(metadataObj);
}
obj.pushKV("metadata", metadata);
obj.pushKV("maxSupply", token.info.nTotalSupply);
if (token.info.type == blsct::TokenType::TOKEN)
obj.pushKV("currentSupply", token.nSupply);
else if (token.info.type == blsct::TokenType::NFT) {
UniValue mintedNft{UniValue::VOBJ};
UniValue mintedNft{UniValue::VARR};
for (auto& it : token.mapMintedNft) {
UniValue nftMetadata{UniValue::VOBJ};
UniValue nftMetadata{UniValue::VARR};
UniValue nftObject{UniValue::VOBJ};
for (auto& it2 : it.second) {
nftMetadata.pushKV(it2.first, it2.second);
UniValue nftMetadataObj{UniValue::VOBJ};
nftMetadataObj.pushKV("key", it2.first);
nftMetadataObj.pushKV("value", it2.second);
nftMetadata.push_back(nftMetadataObj);
}
mintedNft.pushKV(strprintf("%llu", it.first), nftMetadata);
nftObject.pushKV("index", strprintf("%llu", it.first));
nftObject.pushKV("metadata", nftMetadata);
mintedNft.push_back(nftObject);
}
obj.pushKV("mintedNft", mintedNft);
}
Expand Down
15 changes: 11 additions & 4 deletions src/blsct/wallet/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,24 @@ RPCHelpMan getnftbalance()

bool avoid_reuse = GetAvoidReuseFlag(*pwallet, request.params[4]);

UniValue ret(UniValue::VOBJ);
UniValue ret(UniValue::VARR);

for (auto& it : token.mapMintedNft) {
const auto bal = GetBalance(*pwallet, min_depth, avoid_reuse, TokenId(token_id, it.first));

if ((bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0)) > 0) {
UniValue metadata(UniValue::VOBJ);
UniValue retObj(UniValue::VOBJ);

UniValue metadata(UniValue::VARR);
for (auto& md_it : it.second) {
metadata.pushKV(md_it.first, md_it.second);
UniValue metadataObj(UniValue::VOBJ);
metadataObj.pushKV("key", md_it.first);
metadataObj.pushKV("value", md_it.second);
metadata.push_back(metadataObj);
}
ret.pushKV(strprintf("%llu", it.first), metadata);
retObj.pushKV("index", strprintf("%llu", it.first));
retObj.pushKV("metadata", metadata);
ret.push_back(retObj);
}
}

Expand Down
18 changes: 9 additions & 9 deletions test/functional/blsct_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def run_test(self):
tokens = self.nodes[0].listtokens()
assert len(tokens) == 1, "length of tokens is not 1"

self.log.info(f"Created token: {token['tokenId']}")
self.log.info(f"Created NFT: {token['tokenId']}")

assert tokens[0]['type'] == 'nft', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokens[0]['maxSupply'] == 1000, "incorrect max supply"
assert tokens[0]['mintedNft'] == {}, "incorrect current supply"
assert tokens[0]['mintedNft'] == [], "incorrect current supply"

wallet.mintnft(token['tokenId'], 1, blsct_address, {"id": "null"})
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)

tokenInfo = self.nodes[0].gettoken(token['tokenId'])

assert tokenInfo['type'] == 'nft', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['metadata'] ==[{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokenInfo['maxSupply'] == 1000, "incorrect max supply"
assert tokenInfo['mintedNft'] == {'1': {'id': 'null'}}, "incorrect current supply"
assert tokenInfo['mintedNft'] == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect current supply"

self.log.info(f"Minted 1 NFT")

Expand All @@ -92,8 +92,8 @@ def run_test(self):
self.log.info(f"Balance in NODE 1: {nft_balance}")
self.log.info(f"Balance in NODE 2: {nft_balance_2}")

assert nft_balance == {'1': {'id': 'null'}}, "incorrect nft balance in node 1"
assert nft_balance_2 == {}, "incorrect nft balance in node 2"
assert nft_balance == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect nft balance in node 1"
assert nft_balance_2 == [], "incorrect nft balance in node 2"

self.log.info(f"Sending NFT with id #1 to NODE 2")

Expand All @@ -106,8 +106,8 @@ def run_test(self):
self.log.info(f"Balance in NODE 1: {nft_balance}")
self.log.info(f"Balance in NODE 2: {nft_balance_2}")

assert nft_balance_2 == {'1': {'id': 'null'}}, "incorrect nft balance in node 2"
assert nft_balance == {}, "incorrect nft balance in node"
assert nft_balance_2 == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect nft balance in node 2"
assert nft_balance == [], "incorrect nft balance in node"


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions test/functional/blsct_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run_test(self):
self.log.info(f"Created token: {token['tokenId']}")

assert tokens[0]['type'] == 'token', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokens[0]['maxSupply'] == 100000000000, "incorrect max supply"
assert tokens[0]['currentSupply'] == 0, "incorrect current supply"

Expand All @@ -80,7 +80,7 @@ def run_test(self):
tokenInfo = self.nodes[0].gettoken(token['tokenId'])

assert tokenInfo['type'] == 'token', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokenInfo['maxSupply'] == 100000000000, "incorrect max supply"
assert tokenInfo['currentSupply'] == 100000000, "incorrect current supply"

Expand Down

0 comments on commit 85b04a6

Please sign in to comment.