Signed-off-by:Renjith K N <renjithkn@gmail.com>

Signed-off-by: FIRST_NAME LAST_NAME <renjithkn@gamil.com>
Signed-off-by: renjithpta <renjithkn@gmail.com>
This commit is contained in:
FIRST_NAME LAST_NAME 2022-04-01 06:44:10 +00:00 committed by renjithpta
parent 3873cf74c8
commit 62b4131cf5
4 changed files with 75 additions and 63 deletions

View file

@ -40,9 +40,10 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public long balanceOf(final Context ctx, final String owner) { public long balanceOf(final Context ctx, final String owner) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(), owner); final CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(),
QueryResultsIterator<KeyValue> results = stub.getStateByPartialCompositeKey(balanceKey); owner);
final QueryResultsIterator<KeyValue> results = stub.getStateByPartialCompositeKey(balanceKey);
return StreamSupport.stream(results.spliterator(), false).count(); return StreamSupport.stream(results.spliterator(), false).count();
} }
@ -77,9 +78,9 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public boolean isApprovedForAll(final Context ctx, final String owner, final String operator) { public boolean isApprovedForAll(final Context ctx, final String owner, final String operator) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
CompositeKey approvalKey = stub.createCompositeKey(ContractConstants.APPROVAL.getValue(), owner, final CompositeKey approvalKey = stub.createCompositeKey(ContractConstants.APPROVAL.getValue(),
operator); owner, operator);
final String approvalJson = stub.getStringState(approvalKey.toString()); final String approvalJson = stub.getStringState(approvalKey.toString());
if (stringIsNullOrEmpty(approvalJson)) { if (stringIsNullOrEmpty(approvalJson)) {
@ -104,11 +105,11 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void approve(final Context ctx, final String operator, final String tokenId) { public void approve(final Context ctx, final String operator, final String tokenId) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
NFT nft = this.readNft(ctx, tokenId); NFT nft = this.readNft(ctx, tokenId);
String owner = nft.getOwner(); final String owner = nft.getOwner();
boolean operatorApproval = this.isApprovedForAll(ctx, owner, sender); final boolean operatorApproval = this.isApprovedForAll(ctx, owner, sender);
if ((!owner.equalsIgnoreCase(sender)) && (!operatorApproval)) { if ((!owner.equalsIgnoreCase(sender)) && (!operatorApproval)) {
final String errorMessage = String.format( final String errorMessage = String.format(
"The sender %s is not the current owner nor an authorized operator of the token %s.", "The sender %s is not the current owner nor an authorized operator of the token %s.",
@ -117,7 +118,7 @@ public class ERC721TokenContract implements ContractInterface {
} }
nft.setApproved(operator); nft.setApproved(operator);
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
stub.putStringState(nftKey.toString(), nft.toJSONString()); stub.putStringState(nftKey.toString(), nft.toJSONString());
} }
@ -132,10 +133,10 @@ public class ERC721TokenContract implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void setApprovalForAll(final Context ctx, final String operator, final boolean approved) { public void setApprovalForAll(final Context ctx, final String operator, final boolean approved) {
final String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final Approval nftApproval = new Approval(sender, operator, approved); final Approval nftApproval = new Approval(sender, operator, approved);
CompositeKey approvalKey = stub.createCompositeKey(ContractConstants.APPROVAL.getValue(), sender, final CompositeKey approvalKey = stub.createCompositeKey(ContractConstants.APPROVAL.getValue(),
operator); sender, operator);
stub.putStringState(approvalKey.toString(), nftApproval.toJSONString()); stub.putStringState(approvalKey.toString(), nftApproval.toJSONString());
stub.setEvent(ContractConstants.APPROVE_FOR_ALL.getValue(), stub.setEvent(ContractConstants.APPROVE_FOR_ALL.getValue(),
nftApproval.toJSONString().getBytes(UTF_8)); nftApproval.toJSONString().getBytes(UTF_8));
@ -151,7 +152,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String getApproved(final Context ctx, final String tokenId) { public String getApproved(final Context ctx, final String tokenId) {
NFT nft = this.readNft(ctx, tokenId); final NFT nft = this.readNft(ctx, tokenId);
return nft.getApproved(); return nft.getApproved();
} }
@ -166,12 +167,12 @@ public class ERC721TokenContract implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void transferFrom(final Context ctx, final String from, final String to, public void transferFrom(final Context ctx, final String from, final String to,
final String tokenId) { final String tokenId) {
String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
NFT nft = this.readNft(ctx, tokenId); NFT nft = this.readNft(ctx, tokenId);
final String owner = nft.getOwner(); final String owner = nft.getOwner();
final String operator = nft.getApproved(); final String operator = nft.getApproved();
boolean operatorApproval = this.isApprovedForAll(ctx, owner, sender); final boolean operatorApproval = this.isApprovedForAll(ctx, owner, sender);
if ((!owner.equalsIgnoreCase(sender)) && !operator.equalsIgnoreCase(sender) if ((!owner.equalsIgnoreCase(sender)) && !operator.equalsIgnoreCase(sender)
&& !operatorApproval) { && !operatorApproval) {
final String errorMessage = String.format( final String errorMessage = String.format(
@ -193,19 +194,19 @@ public class ERC721TokenContract implements ContractInterface {
// Overwrite a non-fungible token to assign a new owner. // Overwrite a non-fungible token to assign a new owner.
nft.setOwner(to); nft.setOwner(to);
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
stub.putStringState(nftKey.toString(), nft.toJSONString()); stub.putStringState(nftKey.toString(), nft.toJSONString());
// Remove a composite key from the balance of the current owner // Remove a composite key from the balance of the current owner
CompositeKey balanceKeyFrom = stub.createCompositeKey(ContractConstants.BALANCE.getValue(), from, final CompositeKey balanceKeyFrom = stub
tokenId); .createCompositeKey(ContractConstants.BALANCE.getValue(), from, tokenId);
stub.delState(balanceKeyFrom.toString()); stub.delState(balanceKeyFrom.toString());
// Save a composite key to count the balance of a new owner // Save a composite key to count the balance of a new owner
CompositeKey balanceKeyTo = stub.createCompositeKey(ContractConstants.BALANCE.getValue(), to, final CompositeKey balanceKeyTo = stub.createCompositeKey(ContractConstants.BALANCE.getValue(),
tokenId); to, tokenId);
stub.putState(balanceKeyTo.toString(), Character.toString(Character.MIN_VALUE).getBytes(UTF_8)); stub.putState(balanceKeyTo.toString(), Character.toString(Character.MIN_VALUE).getBytes(UTF_8));
// Emit the Transfer event // Emit the Transfer event
@ -268,9 +269,9 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public long totalSupply(final Context ctx) { public long totalSupply(final Context ctx) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue()); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue());
QueryResultsIterator<KeyValue> iterator = stub.getStateByPartialCompositeKey(nftKey); final QueryResultsIterator<KeyValue> iterator = stub.getStateByPartialCompositeKey(nftKey);
return StreamSupport.stream(iterator.spliterator(), false).count(); return StreamSupport.stream(iterator.spliterator(), false).count();
} }
@ -286,14 +287,14 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void setOption(final Context ctx, final String name, final String symbol) { public void setOption(final Context ctx, final String name, final String symbol) {
String clientMSPID = ctx.getClientIdentity().getMSPID(); final String clientMSPID = ctx.getClientIdentity().getMSPID();
// Check minter authorization - this sample assumes Org1 is the issuer with privilege to set the // Check minter authorization - this sample assumes Org1 is the issuer with privilege to set the
// name and symbol // name and symbol
if (!clientMSPID.equalsIgnoreCase(ContractConstants.MINTER_ORG_MSP.getValue())) { if (!clientMSPID.equalsIgnoreCase(ContractConstants.MINTER_ORG_MSP.getValue())) {
throw new ChaincodeException( throw new ChaincodeException(
"Client is not authorized to set the name and symbol of the token"); "Client is not authorized to set the name and symbol of the token");
} }
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
stub.putStringState(ContractConstants.NAMEKEY.getValue(), name); stub.putStringState(ContractConstants.NAMEKEY.getValue(), name);
stub.putStringState(ContractConstants.SYMBOLKEY.getValue(), symbol); stub.putStringState(ContractConstants.SYMBOLKEY.getValue(), symbol);
@ -312,31 +313,41 @@ public class ERC721TokenContract implements ContractInterface {
public NFT mintWithTokenURI(final Context ctx, final String tokenId, final String tokenURI) { public NFT mintWithTokenURI(final Context ctx, final String tokenId, final String tokenURI) {
final String clientMSPID = ctx.getClientIdentity().getMSPID(); final String clientMSPID = ctx.getClientIdentity().getMSPID();
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
if (!clientMSPID.equalsIgnoreCase(ContractConstants.MINTER_ORG_MSP.getValue())) { // Check minter authorization - this sample assumes Org1 is the issuer with privilege to mint a new token if (!clientMSPID.equalsIgnoreCase(ContractConstants.MINTER_ORG_MSP.getValue())) { // Check
// minter
// authorization
// - this
// sample
// assumes
// Org1 is the
// issuer with
// privilege
// to mint a
// new token
throw new ChaincodeException( throw new ChaincodeException(
"Client is not authorized to set the name and symbol of the token", "Client is not authorized to set the name and symbol of the token",
ContractErrors.UNOTHERIZED_SENDER.toString()); ContractErrors.UNOTHERIZED_SENDER.toString());
} }
final String minter = ctx.getClientIdentity().getId(); final String minter = ctx.getClientIdentity().getId();
boolean exists = this.isNftExists(ctx, tokenId); final boolean exists = this.isNftExists(ctx, tokenId);
if (exists) { if (exists) {
throw new ChaincodeException(String.format("The token %s is already minted.", tokenId), throw new ChaincodeException(String.format("The token %s is already minted.", tokenId),
ContractErrors.TOKEN_ALREADY_EXITS.toString()); ContractErrors.TOKEN_ALREADY_EXITS.toString());
} }
NFT nft = new NFT(tokenId, minter, tokenURI, ""); final NFT nft = new NFT(tokenId, minter, tokenURI, "");
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
stub.putStringState(nftKey.toString(), nft.toJSONString()); stub.putStringState(nftKey.toString(), nft.toJSONString());
// A composite key would be balancePrefix.owner.tokenId, which enables partial // A composite key would be balancePrefix.owner.tokenId, which enables partial
// composite key query to find and count all records matching balance.owner.* // composite key query to find and count all records matching balance.owner.*
// An empty value would represent a delete, so we simply insert the null character. // An empty value would represent a delete, so we simply insert the null character.
CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(), minter, final CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(),
tokenId); minter, tokenId);
stub.putStringState(balanceKey.toString(), Character.toString(Character.MIN_VALUE)); stub.putStringState(balanceKey.toString(), Character.toString(Character.MIN_VALUE));
Transfer transferEvent = new Transfer("0x0", minter, tokenId); final Transfer transferEvent = new Transfer("0x0", minter, tokenId);
stub.setEvent(ContractConstants.TRANSFER.getValue(), stub.setEvent(ContractConstants.TRANSFER.getValue(),
transferEvent.toJSONString().getBytes(UTF_8)); transferEvent.toJSONString().getBytes(UTF_8));
return nft; return nft;
@ -350,25 +361,26 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void burn(final Context ctx, final String tokenId) { public void burn(final Context ctx, final String tokenId) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
String owner = ctx.getClientIdentity().getId(); final String owner = ctx.getClientIdentity().getId();
// Check if a caller is the owner of the non-fungible token // Check if a caller is the owner of the non-fungible token
NFT nft = this.readNft(ctx, tokenId); final NFT nft = this.readNft(ctx, tokenId);
if (!nft.getOwner().equalsIgnoreCase(owner)) { if (!nft.getOwner().equalsIgnoreCase(owner)) {
throw new ChaincodeException( throw new ChaincodeException(
String.format("Non-fungible token %s is not owned by %s", tokenId, owner), String.format("Non-fungible token %s is not owned by %s", tokenId, owner),
ContractErrors.TOKEN_NONOWNER.toString()); ContractErrors.TOKEN_NONOWNER.toString());
} }
// Delete the token // Delete the token
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
stub.delState(nftKey.toString()); stub.delState(nftKey.toString());
// Remove a composite key from the balance of the owner // Remove a composite key from the balance of the owner
CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(), owner, final CompositeKey balanceKey = stub.createCompositeKey(ContractConstants.BALANCE.getValue(),
tokenId); owner, tokenId);
stub.delState(balanceKey.toString()); stub.delState(balanceKey.toString());
Transfer transferEvent = new Transfer(owner, "0x0", tokenId); final Transfer transferEvent = new Transfer(owner, "0x0", tokenId);
stub.setEvent(ContractConstants.TRANSFER.getValue(), transferEvent.toJSONString().getBytes(UTF_8)); stub.setEvent(ContractConstants.TRANSFER.getValue(),
transferEvent.toJSONString().getBytes(UTF_8));
} }
/** /**
@ -387,7 +399,7 @@ public class ERC721TokenContract implements ContractInterface {
* is the clientId itself. Users can use this function to get their own account id, which they can * is the clientId itself. Users can use this function to get their own account id, which they can
* then give to others as the payment address. * then give to others as the payment address.
* *
*@param ctx the transaction context * @param ctx the transaction context
* @return sender account id . * @return sender account id .
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
@ -403,9 +415,9 @@ public class ERC721TokenContract implements ContractInterface {
* @return token details. * @return token details.
*/ */
private NFT readNft(final Context ctx, final String tokenId) { private NFT readNft(final Context ctx, final String tokenId) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
String nft = stub.getStringState(nftKey.toString()); final String nft = stub.getStringState(nftKey.toString());
if (stringIsNullOrEmpty(nft)) { if (stringIsNullOrEmpty(nft)) {
final String errorMessage = String.format("Token with id %s not found!.", tokenId); final String errorMessage = String.format("Token with id %s not found!.", tokenId);
throw new ChaincodeException(errorMessage, ContractErrors.TOKEN_NOT_FOUND.toString()); throw new ChaincodeException(errorMessage, ContractErrors.TOKEN_NOT_FOUND.toString());
@ -421,9 +433,9 @@ public class ERC721TokenContract implements ContractInterface {
* @return true if token exits else false. * @return true if token exits else false.
*/ */
private boolean isNftExists(final Context ctx, final String tokenId) { private boolean isNftExists(final Context ctx, final String tokenId) {
ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId); final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue(), tokenId);
String nft = stub.getStringState(nftKey.toString()); final String nft = stub.getStringState(nftKey.toString());
return ((stringIsNullOrEmpty(nft)) ? false : true); return ((stringIsNullOrEmpty(nft)) ? false : true);
} }

View file

@ -110,8 +110,8 @@ public final class Approval {
* @return * @return
*/ */
public static Approval fromJSONString(final String data) { public static Approval fromJSONString(final String data) {
JSONObject json = new JSONObject(data); final JSONObject json = new JSONObject(data);
Approval approver = new Approval(json.getString("owner"), json.getString("operator"), final Approval approver = new Approval(json.getString("owner"), json.getString("operator"),
new Boolean(json.getBoolean("approved"))); new Boolean(json.getBoolean("approved")));
return approver; return approver;

View file

@ -144,8 +144,8 @@ public final class NFT implements Serializable {
*/ */
public static NFT fromJSONString(final String data) { public static NFT fromJSONString(final String data) {
JSONObject json = new JSONObject(data); final JSONObject json = new JSONObject(data);
NFT nft = new NFT(json.getString("tokenId"), json.getString("owner"), final NFT nft = new NFT(json.getString("tokenId"), json.getString("owner"),
json.getString("tokenURI"), json.getString("approved")); json.getString("tokenURI"), json.getString("approved"));
return nft; return nft;

View file

@ -381,7 +381,7 @@ public class ERC721TokenContractTest {
when(ctx.getStub()).thenReturn(stub); when(ctx.getStub()).thenReturn(stub);
when(stub.getStringState(ContractConstants.NAMEKEY.getValue())).thenReturn("ANFT"); when(stub.getStringState(ContractConstants.NAMEKEY.getValue())).thenReturn("ANFT");
ERC721TokenContract contract = new ERC721TokenContract(); ERC721TokenContract contract = new ERC721TokenContract();
String name = contract.getName(ctx); final String name = contract.getName(ctx);
assertThat(name).isEqualTo("ANFT"); assertThat(name).isEqualTo("ANFT");
} }
@ -392,7 +392,7 @@ public class ERC721TokenContractTest {
ChaincodeStub stub = mock(ChaincodeStub.class); ChaincodeStub stub = mock(ChaincodeStub.class);
when(ctx.getStub()).thenReturn(stub); when(ctx.getStub()).thenReturn(stub);
ERC721TokenContract contract = new ERC721TokenContract(); ERC721TokenContract contract = new ERC721TokenContract();
NFT nft = new NFT("101", "Alice", "http://test.com", "Bob"); final NFT nft = new NFT("101", "Alice", "http://test.com", "Bob");
CompositeKey ck = mock(CompositeKey.class); CompositeKey ck = mock(CompositeKey.class);
when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101"); when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101");
@ -421,7 +421,7 @@ public class ERC721TokenContractTest {
when(stub.getStateByPartialCompositeKey(ck)).thenReturn(new MockAssetResultsIterator(list)); when(stub.getStateByPartialCompositeKey(ck)).thenReturn(new MockAssetResultsIterator(list));
ERC721TokenContract contract = new ERC721TokenContract(); ERC721TokenContract contract = new ERC721TokenContract();
long total = contract.totalSupply(ctx); final long total = contract.totalSupply(ctx);
assertThat(total).isEqualTo(2L); assertThat(total).isEqualTo(2L);
} }
@ -436,7 +436,7 @@ public class ERC721TokenContractTest {
Context ctx = mock(Context.class); Context ctx = mock(Context.class);
ChaincodeStub stub = mock(ChaincodeStub.class); ChaincodeStub stub = mock(ChaincodeStub.class);
when(ctx.getStub()).thenReturn(stub); when(ctx.getStub()).thenReturn(stub);
NFT nft = new NFT("101", "Alice", "DummyURI", ""); final NFT nft = new NFT("101", "Alice", "DummyURI", "");
CompositeKey ck = mock(CompositeKey.class); CompositeKey ck = mock(CompositeKey.class);
when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101"); when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101");
when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck); when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck);
@ -453,7 +453,7 @@ public class ERC721TokenContractTest {
when(ci.getMSPID()).thenReturn("Org1MSP"); when(ci.getMSPID()).thenReturn("Org1MSP");
when(ci.getId()).thenReturn("Alice"); when(ci.getId()).thenReturn("Alice");
ERC721TokenContract contract = new ERC721TokenContract(); ERC721TokenContract contract = new ERC721TokenContract();
NFT response = contract.mintWithTokenURI(ctx, "101", "DummyURI"); final NFT response = contract.mintWithTokenURI(ctx, "101", "DummyURI");
verify(stub).putStringState(ck.toString(), nft.toJSONString()); verify(stub).putStringState(ck.toString(), nft.toJSONString());
verify(stub).putStringState(ck2.toString(), "\u0000"); verify(stub).putStringState(ck2.toString(), "\u0000");
@ -466,7 +466,7 @@ public class ERC721TokenContractTest {
Context ctx = mock(Context.class); Context ctx = mock(Context.class);
ChaincodeStub stub = mock(ChaincodeStub.class); ChaincodeStub stub = mock(ChaincodeStub.class);
when(ctx.getStub()).thenReturn(stub); when(ctx.getStub()).thenReturn(stub);
NFT nft = new NFT("101", "Alice", "DummyURI", ""); final NFT nft = new NFT("101", "Alice", "DummyURI", "");
CompositeKey ck = mock(CompositeKey.class); CompositeKey ck = mock(CompositeKey.class);
when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101"); when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101");
when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck); when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck);
@ -490,7 +490,7 @@ public class ERC721TokenContractTest {
Context ctx = mock(Context.class); Context ctx = mock(Context.class);
ChaincodeStub stub = mock(ChaincodeStub.class); ChaincodeStub stub = mock(ChaincodeStub.class);
when(ctx.getStub()).thenReturn(stub); when(ctx.getStub()).thenReturn(stub);
NFT nft = new NFT("101", "Alice", "DummyURI", ""); final NFT nft = new NFT("101", "Alice", "DummyURI", "");
CompositeKey ck = mock(CompositeKey.class); CompositeKey ck = mock(CompositeKey.class);
when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101"); when(ck.toString()).thenReturn(ContractConstants.NFT.getValue() + "101");
when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck); when(stub.createCompositeKey(ContractConstants.NFT.getValue(), "101")).thenReturn(ck);