Skip to content

Commit

Permalink
sc deploy integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Jul 7, 2023
1 parent 8f2155a commit 8b1bd58
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
106 changes: 106 additions & 0 deletions integrationtests/scDeploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//go:build integrationtests

package integrationtests

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

"github.com/multiversx/mx-chain-core-go/core"
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 TestTransactionWithSCDeploy(t *testing.T) {
setLogLevelDebug()

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

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

txHash := []byte("scDeployHash")
header := &dataBlock.Header{
Round: 50,
TimeStamp: 5040,
ShardID: 2,
}
body := &dataBlock.Body{
MiniBlocks: dataBlock.MiniBlockSlice{
{
Type: dataBlock.TxBlock,
SenderShardID: 2,
ReceiverShardID: 2,
TxHashes: [][]byte{txHash},
},
},
}
sndAddress := "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0"
tx := &transaction.Transaction{
Nonce: 1,
SndAddr: decodeAddress(sndAddress),
RcvAddr: decodeAddress("erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"),
GasLimit: 1000000000,
GasPrice: 2000000,
Data: []byte("0061736d01000000010d036000006000017f60027f7f00023e0303656e760f6765744e756d417267756d656e7473000103656e760b7369676e616c4572726f72000203656e760e636865636b4e6f5061796d656e74000003030200000503010003060f027f00419980080b7f0041a080080b073705066d656d6f7279020004696e697400030863616c6c4261636b00040a5f5f646174615f656e6403000b5f5f686561705f6261736503010a180212001002100004404180800841191001000b0b0300010b0b210100418080080b1977726f6e67206e756d626572206f6620617267756d656e7473@0500@0502"),
Value: big.NewInt(0),
}

txInfo := &outport.TxInfo{
Transaction: tx,
FeeInfo: &outport.FeeInfo{
GasUsed: 1130820,
Fee: big.NewInt(764698200000000),
InitialPaidFee: big.NewInt(773390000000000),
},
ExecutionOrder: 0,
}

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
hex.EncodeToString(txHash): txInfo,
},
Logs: []*outport.LogData{
{
TxHash: hex.EncodeToString([]byte("h1")),
Log: &transaction.Log{
Address: decodeAddress(sndAddress),
Events: []*transaction.Event{
{
Address: decodeAddress(sndAddress),
Identifier: []byte(core.SCDeployIdentifier),
Topics: [][]byte{decodeAddress("erd1qqqqqqqqqqqqqpgq4t2tqxpst9a6qttpak8cz8wvz6a0nses5qfqel6rhy"), decodeAddress("erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0")},
},
nil,
},
},
},
},
}
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards))
require.Nil(t, err)

ids := []string{hex.EncodeToString(txHash)}
genericResponse := &GenericResponse{}
err = esClient.DoMultiGet(ids, indexerData.TransactionsIndex, true, genericResponse)
require.Nil(t, err)

require.JSONEq(t,
readExpectedResult("./testdata/scDeploy/tx-sc-deploy.json"),
string(genericResponse.Docs[0].Source),
)

ids = []string{"erd1qqqqqqqqqqqqqpgq4t2tqxpst9a6qttpak8cz8wvz6a0nses5qfqel6rhy"}
err = esClient.DoMultiGet(ids, indexerData.SCDeploysIndex, true, genericResponse)
require.Nil(t, err)

require.JSONEq(t,
readExpectedResult("./testdata/scDeploy/deploy.json"),
string(genericResponse.Docs[0].Source),
)
}
6 changes: 6 additions & 0 deletions integrationtests/testdata/scDeploy/deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deployTxHash": "6831",
"deployer": "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0",
"timestamp": 5040,
"upgrades": []
}
24 changes: 24 additions & 0 deletions integrationtests/testdata/scDeploy/tx-sc-deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"miniBlockHash": "1703039e791823d0e722a0d3df76c87786fb5074d2b333c98a870335b418a97d",
"nonce": 1,
"round": 50,
"value": "0",
"valueNum": 0,
"receiver": "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu",
"sender": "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0",
"receiverShard": 2,
"senderShard": 2,
"gasPrice": 2000000,
"gasLimit": 1000000000,
"gasUsed": 1130820,
"fee": "764698200000000",
"feeNum": 0.0007646982,
"initialPaidFee": "773390000000000",
"data": "MDA2MTczNmQwMTAwMDAwMDAxMGQwMzYwMDAwMDYwMDAwMTdmNjAwMjdmN2YwMDAyM2UwMzAzNjU2ZTc2MGY2NzY1NzQ0ZTc1NmQ0MTcyNjc3NTZkNjU2ZTc0NzMwMDAxMDM2NTZlNzYwYjczNjk2NzZlNjE2YzQ1NzI3MjZmNzIwMDAyMDM2NTZlNzYwZTYzNjg2NTYzNmI0ZTZmNTA2MTc5NmQ2NTZlNzQwMDAwMDMwMzAyMDAwMDA1MDMwMTAwMDMwNjBmMDI3ZjAwNDE5OTgwMDgwYjdmMDA0MWEwODAwODBiMDczNzA1MDY2ZDY1NmQ2ZjcyNzkwMjAwMDQ2OTZlNjk3NDAwMDMwODYzNjE2YzZjNDI2MTYzNmIwMDA0MGE1ZjVmNjQ2MTc0NjE1ZjY1NmU2NDAzMDAwYjVmNWY2ODY1NjE3MDVmNjI2MTczNjUwMzAxMGExODAyMTIwMDEwMDIxMDAwMDQ0MDQxODA4MDA4NDExOTEwMDEwMDBiMGIwMzAwMDEwYjBiMjEwMTAwNDE4MDgwMDgwYjE5Nzc3MjZmNmU2NzIwNmU3NTZkNjI2NTcyMjA2ZjY2MjA2MTcyNjc3NTZkNjU2ZTc0NzNAMDUwMEAwNTAy",
"signature": "",
"timestamp": 5040,
"status": "success",
"searchOrder": 0,
"isScCall": true,
"operation": "scDeploy"
}
2 changes: 1 addition & 1 deletion integrationtests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CreateElasticProcessor(
DBClient: esClient,
EnabledIndexes: []string{dataindexer.TransactionsIndex, dataindexer.LogsIndex, dataindexer.AccountsESDTIndex, dataindexer.ScResultsIndex,
dataindexer.ReceiptsIndex, dataindexer.BlockIndex, dataindexer.AccountsIndex, dataindexer.TokensIndex, dataindexer.TagsIndex,
dataindexer.OperationsIndex, dataindexer.DelegatorsIndex, dataindexer.ESDTsIndex},
dataindexer.OperationsIndex, dataindexer.DelegatorsIndex, dataindexer.ESDTsIndex, dataindexer.SCDeploysIndex},
Denomination: 18,
}

Expand Down

0 comments on commit 8b1bd58

Please sign in to comment.