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

Mx 15792 esdt prefix updates and fixes #6466

Open
wants to merge 8 commits into
base: feat/esdt-prefix
Choose a base branch
from

Conversation

axenteoctavian
Copy link

Reasoning behind the pull request

  • ESDT prefix fixes for some token types

Proposed changes

  • Cross-chain token checker in esdtDataStorage to bypass the change of token type
  • Refactored tests, added cross-shard transactions, added multiple checks in user account and system account

Testing procedure

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@axenteoctavian axenteoctavian self-assigned this Sep 17, 2024
Copy link
Contributor

@mariusmihaic mariusmihaic left a comment

Choose a reason for hiding this comment

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

We should not merge commented untested code

type crossChainTokenChecker struct {
}

func NewCrossChainTokenChecker() *crossChainTokenChecker {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comm

return &crossChainTokenChecker{}
}

// IsCrossChainOperation does nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// IsCrossChainOperation does nothing
// IsCrossChainOperation returns false

return false
}

// IsCrossChainOperationAllowed does nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// IsCrossChainOperationAllowed does nothing
// IsCrossChainOperationAllowed returns false nothing

}

// IsCrossChainOperation does nothing
func (ctc *crossChainTokenChecker) IsCrossChainOperation(tokenID []byte) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (ctc *crossChainTokenChecker) IsCrossChainOperation(tokenID []byte) bool {
func (ctc *crossChainTokenChecker) IsCrossChainOperation(_ []byte) bool {

}

// IsCrossChainOperationAllowed does nothing
func (ctc *crossChainTokenChecker) IsCrossChainOperationAllowed(address []byte, tokenID []byte) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (ctc *crossChainTokenChecker) IsCrossChainOperationAllowed(address []byte, tokenID []byte) bool {
func (ctc *crossChainTokenChecker) IsCrossChainOperationAllowed(_ []byte, _ []byte) bool {

nftV2 := sovChainPrefix + "-NFTV2-a1b2c3"
nftV2Nonce := uint64(10)
token := sovChainPrefix + "-TKN-1q2w3e"

bridgedInTokens := make([]chainSim.ArgsDepositToken, 0)
bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why were these removed from these tests?

Copy link
Author

Choose a reason for hiding this comment

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

NonFungible type is not accepted anymore

@@ -38,7 +39,7 @@ func TestChainSimulator_ExecuteMintBurnBridgeOpForESDTTokensWithPrefixAndTransfe
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
NumOfShards: 1,
NumOfShards: 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Amount: big.NewInt(1),
Type: core.NonFungibleV2,
})
//bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not ok.
We should not merge commented untested code !

Copy link
Author

Choose a reason for hiding this comment

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

As the TODO says, the contract uses structs from the rust framework and we need to wait for rust framework to be updated to accept all new esdt types. I will create another PR with tests for create/burn for all esdt types but on different contract that is not using framework structs.

checkTokenDataInAccount(t, cs, token, esdtSafeEncoded, big.NewInt(0))
receiverToken.Amount = remainingTokenAmount

if remainingTokenAmount.Cmp(big.NewInt(0)) > 0 {
Copy link
Contributor

@mariusmihaic mariusmihaic Sep 18, 2024

Choose a reason for hiding this comment

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

Why make this "same shard" transfer based on remaining amount?

You seem to always send tokens above to receiver, then in "same shard" you also send from receiver, so you should always have tokens in receiver

Copy link
Author

Choose a reason for hiding this comment

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

  • The wallet in shard 0 sends tokens to receiver in shard 2
  • The receiver will deposit (burn) in the bridge contract in shard 1
  • The receiver in shard 2 sends tokens to receiver2 in same shard
    This check is to skip the NFT tokens because after deposit quantity is 0

chainSim.TransferESDT(t, cs, sender.Bytes, receiver.Bytes, senderNonce, token.Identifier, amountToSend)
} else {
chainSim.TransferESDTNFT(t, cs, sender.Bytes, receiver.Bytes, senderNonce, token.Identifier, token.Nonce, amountToSend)
err := cs.GenerateBlocks(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why generate extra blocks here?
Because cross shard txs? And why it works for TransferESDT without generated blocks?

Copy link
Author

Choose a reason for hiding this comment

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

For NFT transfer, sender == receiver in arguments and actual receiver is in input data in tx. So the chain simulator verifies the status on the same shard and is successful in 1 block. Then I need to wait 3 more blocks so the actual receiver will receive the tokens because is in different shard.

Copy link
Contributor

@BeniaminDrasovean BeniaminDrasovean left a comment

Choose a reason for hiding this comment

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

Just what Marius said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants