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

Esdt improvements integration #282

Merged
merged 8 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion data/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ package data

import (
"time"

"github.com/multiversx/mx-chain-core-go/core"
)

const metaESDT = "MetaESDT"

// NFTDataUpdate will contain the update information for an NFT or SFT
type NFTDataUpdate struct {
Identifier string
Address string
NewCreator string
URIsToAdd [][]byte
NewAttributes []byte
Address string
Freeze bool
UnFreeze bool
Pause bool
UnPause bool
SetURIs bool
NewRoyalties core.OptionalUint32
NewMetaData *TokenMetaData
}

// ResponseTokens is the structure for the tokens response
Expand Down Expand Up @@ -51,6 +57,7 @@ type TokenInfo struct {
Data *TokenMetaData `json:"data,omitempty"`
OwnersHistory []*OwnerData `json:"ownersHistory,omitempty"`
TransferOwnership bool `json:"-"`
ChangeToDynamic bool `json:"-"`
Properties *TokenProperties `json:"properties,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.37.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a h1:7M+jXVlnl43zd2NuimL1KnAVAdpUr/QoHqG0TUKoyaM=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
96 changes: 96 additions & 0 deletions integrationtests/issueTokenAndChangeType_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//go:build integrationtests

package integrationtests

import (
"context"
"encoding/hex"
"math/big"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/alteredAccount"
dataBlock "github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/outport"
"github.com/multiversx/mx-chain-core-go/data/transaction"
indexerdata "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
"github.com/stretchr/testify/require"
)

func TestIssueTokenAndChangeToDynamic(t *testing.T) {
setLogLevelDebug()

esClient, err := createESClient(esURL)
require.Nil(t, err)

esProc, err := CreateElasticProcessor(esClient)
require.Nil(t, err)

body := &dataBlock.Body{}
header := &dataBlock.Header{
Round: 50,
TimeStamp: 5040,
ShardID: core.MetachainShardId,
}

address1 := "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv"
pool := &outport.TransactionPool{
Logs: []*outport.LogData{
{
TxHash: hex.EncodeToString([]byte("h1")),
Log: &transaction.Log{
Address: decodeAddress(address1),
Events: []*transaction.Event{
{
Address: decodeAddress(address1),
Identifier: []byte("issueSemiFungible"),
Topics: [][]byte{[]byte("CON-abcd"), []byte("semi-token"), []byte("SEMI"), []byte(core.SemiFungibleESDT)},
},
{
Address: decodeAddress(address1),
Identifier: []byte("upgradeProperties"),
Topics: [][]byte{[]byte("CON-abcd"), big.NewInt(0).Bytes(), []byte("canUpgrade"), []byte("true")},
},
nil,
},
},
},
},
}

err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, map[string]*alteredAccount.AlteredAccount{}, testNumOfShards))
require.Nil(t, err)

ids := []string{"CON-abcd"}
genericResponse := &GenericResponse{}
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TokensIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/issueTokenAndChangeType/token.json"), string(genericResponse.Docs[0].Source))

header.TimeStamp = 10_000
pool = &outport.TransactionPool{
Logs: []*outport.LogData{
{
TxHash: hex.EncodeToString([]byte("h1")),
Log: &transaction.Log{
Address: decodeAddress(address1),
Events: []*transaction.Event{
{
Address: decodeAddress(address1),
Identifier: []byte("changeToDynamic"),
Topics: [][]byte{[]byte("CON-abcd"), []byte("semi-token"), []byte("SEMI"), []byte(core.DynamicSFTESDT)},
},
nil,
},
},
},
},
}

err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, map[string]*alteredAccount.AlteredAccount{}, testNumOfShards))
require.Nil(t, err)

err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TokensIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/issueTokenAndChangeType/token-with-new-type.json"), string(genericResponse.Docs[0].Source))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "semi-token",
"ticker": "SEMI",
"token": "CON-abcd",
"issuer": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"currentOwner": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"numDecimals": 0,
"type": "DynamicSemiFungibleESDT",
"timestamp": 5040,
"ownersHistory": [
{
"address": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"timestamp": 5040
}
],
"properties": {
"canMint": false,
"canBurn": false,
"canUpgrade": true,
"canTransferNFTCreateRole": false,
"canAddSpecialRoles": false,
"canPause": false,
"canFreeze": false,
"canWipe": false,
"canChangeOwner": false,
"canCreateMultiShard": false
},
"changedToDynamicTimestamp": 10000
}
28 changes: 28 additions & 0 deletions integrationtests/testdata/issueTokenAndChangeType/token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "semi-token",
"ticker": "SEMI",
"token": "CON-abcd",
"issuer": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"currentOwner": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"numDecimals": 0,
"type": "SemiFungibleESDT",
"timestamp": 5040,
"ownersHistory": [
{
"address": "erd1k04pxr6c0gvlcx4rd5fje0a4uy33axqxwz0fpcrgtfdy3nrqauqqgvxprv",
"timestamp": 5040
}
],
"properties": {
"canMint": false,
"canBurn": false,
"canUpgrade": true,
"canTransferNFTCreateRole": false,
"canAddSpecialRoles": false,
"canPause": false,
"canFreeze": false,
"canWipe": false,
"canChangeOwner": false,
"canCreateMultiShard": false
}
}
4 changes: 4 additions & 0 deletions integrationtests/testdata/mappings/esdts.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
"type": "date",
"format": "epoch_second"
},
"changedToDynamicTimestamp": {
"type": "date",
"format": "epoch_second"
},
"token": {
"type": "text"
},
Expand Down
21 changes: 21 additions & 0 deletions integrationtests/testdata/updateNFT/token-after-new-creator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"identifier": "NFT-abcd-0e",
"token": "NFT-abcd",
"numDecimals": 0,
"nonce": 14,
"timestamp": 5040,
"data": {
"uris": [
"dXJp",
"dXJp",
"dXJp",
"dXJp",
"dXJp"
],
"nonEmptyURIs": true,
"whiteListedStorage": false,
"attributes": "c29tZXRoaW5n",
"creator": "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0"
},
"frozen": false
}
22 changes: 22 additions & 0 deletions integrationtests/testdata/updateNFT/token-after-new-royalties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"identifier": "NFT-abcd-0e",
"token": "NFT-abcd",
"numDecimals": 0,
"nonce": 14,
"timestamp": 5040,
"data": {
"uris": [
"dXJp",
"dXJp",
"dXJp",
"dXJp",
"dXJp"
],
"nonEmptyURIs": true,
"whiteListedStorage": false,
"attributes": "c29tZXRoaW5n",
"creator": "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0",
"royalties": 100
},
"frozen": false
}
16 changes: 16 additions & 0 deletions integrationtests/testdata/updateNFT/token-after-recreate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"identifier": "NEW-abcd-64",
"token": "NEW-abcd",
"numDecimals": 0,
"nonce": 100,
"timestamp": 5040,
"data": {
"uris": [
"dXJp"
],
"whiteListedStorage": false,
"name": "token",
"nonEmptyURIs": true,
"hash": "aGFzaA=="
}
}
20 changes: 20 additions & 0 deletions integrationtests/testdata/updateNFT/token-after-set-new-uris.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"identifier": "NFT-abcd-0e",
"token": "NFT-abcd",
"numDecimals": 0,
"nonce": 14,
"timestamp": 5040,
"data": {
"uris": [
"dXJp",
"dXJp",
"dXJp",
"dXJp",
"dXJp"
],
"nonEmptyURIs": true,
"whiteListedStorage": false,
"attributes": "c29tZXRoaW5n"
},
"frozen": false
}
16 changes: 16 additions & 0 deletions integrationtests/testdata/updateNFT/token-after-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"identifier": "NEW-abcd-64",
"token": "NEW-abcd",
"numDecimals": 0,
"nonce": 100,
"timestamp": 5040,
"data": {
"uris": [
"dXJp"
],
"whiteListedStorage": false,
"name": "token-second",
"nonEmptyURIs": true,
"hash": "aGFzaA=="
}
}
16 changes: 16 additions & 0 deletions integrationtests/testdata/updateNFT/token-before-recreate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"identifier": "NEW-abcd-64",
"token": "NEW-abcd",
"numDecimals": 0,
"nonce": 100,
"timestamp": 5040,
"data": {
"name": "token-token-token",
"uris": [
"dXJp",
"dXJp"
],
"nonEmptyURIs": true,
"whiteListedStorage": false
}
}
Loading
Loading