-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
En 9146 nfts like esdt unit tests #2899
En 9146 nfts like esdt unit tests #2899
Conversation
|
||
checkNftData(t, nodes[1].OwnAccount.Address, nodes, tokenIdentifier, &nftMetaData, false) | ||
|
||
// increase quantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change comment to decrease quantity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
time.Sleep(time.Second) | ||
|
||
// the token data is removed from trie if the quantity is 0, so we should not find it | ||
checkNftData(t, nodes[1].OwnAccount.Address, nodes, tokenIdentifier, &nftMetaData, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you send nftMetaData over if you want to find it empty ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored
|
||
///////////------- send token issue | ||
|
||
issueNFT(nodes, core.SemiFungibleESDT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part of issue and set special roles may be taken out into a separate function. like prepareESDTNFTData and gets some arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. this prepare function has a lot of arguments, but with this refactoring I managed to reduce the code duplication 👍
tokenIdentifierPlusNonce = append(tokenIdentifierPlusNonce, big.NewInt(0).SetUint64(1).Bytes()...) | ||
esdtData := getESDTTokenData(t, address, nodes, string(tokenIdentifierPlusNonce)) | ||
|
||
if shouldNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this bool is not needed. you can use args.quantity == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. nice idea 👍
) | ||
} | ||
|
||
func TestESDTSemiFungibleTokenTransferCrossShard(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function too long. make smaller reusable functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
) | ||
} | ||
|
||
func TestESDTSemiFungibleTokenCreateAddAndBurn(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted the functionality for preparing
…nit-tests # Conflicts: # go.mod # go.sum
- changed transfer unit tests to work with smart contracts calls
…m/ElrondNetwork/elrond-go into EN-9146-nfts-like-esdt-unit-tests � Conflicts: � process/smartContract/builtInFunctions/esdtNFTTransfer_test.go
…sc-tests tNFT Transfer create role integration test
|
||
nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(1).Bytes()) | ||
quantityToSend := int64(1) | ||
quantityToBurnArg := hex.EncodeToString(big.NewInt(quantityToSend).Bytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quantityToTransferArg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(1).Bytes()) | ||
quantityToSend := int64(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quantityToTransfer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
require.Equal(t, newGasCost, eqf.funcGasCost) | ||
} | ||
|
||
func TestEsdtNFTAddQuantity_ProcessBuiltinFunctionErrorOncheckESDTNFTCreateBurnAddInput(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnCheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
require.Equal(t, newGasCost, ebf.funcGasCost) | ||
} | ||
|
||
func TestEsdtNFTBurnFunc_ProcessBuiltinFunctionErrorOncheckESDTNFTCreateBurnAddInput(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnCheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if err != nil { | ||
return nil, err | ||
if isNew { | ||
return nil, process.ErrNewNFTDataOnSenderAddress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return esdtData, process.ErrNewNFTDataOnSenderAddress ? or return nil, true, nil -> at line 222 ?
(esdtData is not used in the caller side if isNew is true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. on sender it should error. as you must have it in order to transfer / burn or anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is correct as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -214,9 +216,6 @@ func (e *esdtNFTCreateRoleTransfer) executeTransferNFTCreateChangeAtNextOwner( | |||
acntDst state.UserAccountHandler, | |||
vmInput *vmcommon.ContractCallInput, | |||
) error { | |||
if check.IfNil(acntDst) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be kept, otherwise it will panic in saveLatestNonce method called below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is checked above. on line 71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
destAcc, _ := e.accounts.LoadAccount(addr) | ||
userAcc := destAcc.(state.UserAccountHandler) | ||
nonce, _ := getLatestNonce(userAcc, tokenID) | ||
assert.Equal(t, nonce, expectedNonce) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Equal(t, expectedNonce, nonce)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
roles := &esdt.ESDTRoles{ | ||
Roles: make([][]byte, 0), | ||
} | ||
if len(marshaledData) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition could be moved with || in L116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
vm/systemSmartContracts/esdt_test.go
Outdated
require.Equal(t, vmcommon.Ok, retCode) | ||
} | ||
|
||
func TestEsdt_SetSpecialRoleSemiNFTShouldErr(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SFT or SemiFT instead SemiNFT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1 @@ | |||
package esdt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be filled in next prs.
@@ -371,7 +372,7 @@ func (bh *BlockChainHookImpl) ProcessBuiltInFunction(input *vmcommon.ContractCal | |||
} | |||
} | |||
|
|||
if !check.IfNil(dstAccount) { | |||
if !check.IfNil(dstAccount) && !bytes.Equal(input.CallerAddr, input.RecipientAddr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will get clearer if we write it as:
shouldSaveDestination := !check.IfNil(dstAccount) && !bytes.Equal(sndAccount.AddressBytes(), dstAccount.AddressBytes)
if shouldSaveDestination{
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave as it is.
@@ -159,6 +159,11 @@ func (builder *txDataBuilder) CanBurn(prop bool) *txDataBuilder { | |||
return builder.Str("canBurn").Bool(prop) | |||
} | |||
|
|||
// CanTransferNFTCreateRole appends "canTransferNFTCreateRole" followed by the provided boolean value. | |||
func (builder *txDataBuilder) CanTransferNFTCreateRole(prop bool) *txDataBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Unit tests for new added ESDT NFT components