-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathaccountsESDTRollback_test.go
More file actions
100 lines (87 loc) · 2.74 KB
/
accountsESDTRollback_test.go
File metadata and controls
100 lines (87 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//go:build integrationtests
package integrationtests
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"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/esdt"
"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 TestAccountsESDTDeleteOnRollback(t *testing.T) {
setLogLevelDebug()
esClient, err := createESClient(esURL)
require.Nil(t, err)
esdtToken := &esdt.ESDigitalToken{
Value: big.NewInt(1000),
Properties: []byte("3032"),
TokenMetaData: &esdt.MetaData{
Creator: []byte("creator"),
},
}
addr := "erd1sqy2ywvswp09ef7qwjhv8zwr9kzz3xas6y2ye5nuryaz0wcnfzzsnq0am3"
coreAlteredAccounts := map[string]*alteredAccount.AlteredAccount{
addr: {
Address: addr,
Tokens: []*alteredAccount.AccountTokenData{
{
Identifier: "TOKEN-eeee",
Nonce: 2,
Balance: "1000",
MetaData: &alteredAccount.TokenMetaData{
Creator: "creator",
},
Properties: "3032",
},
},
},
}
esProc, err := CreateElasticProcessor(esClient)
require.Nil(t, err)
// CREATE SEMI-FUNGIBLE TOKEN
esdtDataBytes, _ := json.Marshal(esdtToken)
pool := &outport.TransactionPool{
Logs: []*outport.LogData{
{
TxHash: hex.EncodeToString([]byte("h1")),
Log: &transaction.Log{
Events: []*transaction.Event{
{
Address: decodeAddress(addr),
Identifier: []byte(core.BuiltInFunctionESDTNFTCreate),
Topics: [][]byte{[]byte("TOKEN-eeee"), big.NewInt(2).Bytes(), big.NewInt(1).Bytes(), esdtDataBytes},
},
nil,
},
},
},
},
}
body := &dataBlock.Body{}
header := &dataBlock.Header{
Round: 50,
TimeStamp: 5040,
ShardID: 2,
}
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, coreAlteredAccounts, testNumOfShards))
require.Nil(t, err)
ids := []string{fmt.Sprintf("%s-TOKEN-eeee-02", addr)}
genericResponse := &GenericResponse{}
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.AccountsESDTIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/accountsESDTRollback/account-after-create.json"), string(genericResponse.Docs[0].Source))
// DO ROLLBACK
err = esProc.RemoveAccountsESDT(2, 5040000)
require.Nil(t, err)
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.AccountsESDTIndex, true, genericResponse)
require.Nil(t, err)
require.False(t, genericResponse.Docs[0].Found)
}