Skip to content
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

Merged
merged 29 commits into from
Mar 18, 2021

Conversation

bogdan-rosianu
Copy link
Contributor

Unit tests for new added ESDT NFT components

@sasurobert sasurobert self-requested a review March 15, 2021 12:06

checkNftData(t, nodes[1].OwnAccount.Address, nodes, tokenIdentifier, &nftMetaData, false)

// increase quantity
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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 ?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function too long

Copy link
Contributor Author

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

@sasurobert sasurobert marked this pull request as ready for review March 16, 2021 19:30
@sasurobert sasurobert changed the title [WIP] En 9146 nfts like esdt unit tests En 9146 nfts like esdt unit tests Mar 16, 2021
sasurobert
sasurobert previously approved these changes Mar 16, 2021
@SebastianMarian SebastianMarian self-requested a review March 16, 2021 20:06
sasurobert
sasurobert previously approved these changes Mar 17, 2021

nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(1).Bytes())
quantityToSend := int64(1)
quantityToBurnArg := hex.EncodeToString(big.NewInt(quantityToSend).Bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quantityToTransferArg

Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quantityToTransfer

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnCheck

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnCheck

Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

require.Equal(t, vmcommon.Ok, retCode)
}

func TestEsdt_SetSpecialRoleSemiNFTShouldErr(t *testing.T) {
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty file?

Copy link
Contributor

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) {
Copy link
Contributor

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{
....

Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@sasurobert sasurobert merged commit e771ab4 into feat/eip-esdt-local-mint Mar 18, 2021
@sasurobert sasurobert deleted the EN-9146-nfts-like-esdt-unit-tests branch March 18, 2021 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants