Skip to content

Commit

Permalink
Merge branch 'master' into merge-master-into-feat-sovereign-9-oct-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Oct 9, 2024
2 parents 17f4760 + 0e39df8 commit 7dc6e64
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 5 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish Docker image

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.20.7
id: go

- name: Get dependencies
run: |
go mod download
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: multiversx/elastic-indexer

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20.5 as builder
FROM golang:1.20.7 as builder

RUN apt-get update && apt-get install -y

Expand Down
200 changes: 200 additions & 0 deletions integrationtests/esdtTransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,203 @@ func TestESDTTransferTooMuchGasProvided(t *testing.T) {

require.JSONEq(t, readExpectedResult("./testdata/esdtTransfer/esdt-transfer.json"), string(genericResponse.Docs[0].Source))
}

func TestESDTTransferCrossShardWithRefundOnSourceShard(t *testing.T) {
esClient, err := createESClient(esURL)
require.Nil(t, err)

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

txHash := []byte("esdtTransferCross")
header := &dataBlock.Header{
Round: 50,
TimeStamp: 10101,
ShardID: 2,
}

scrHash1 := []byte("scrHash1ESDTTransferOnSourceShard")
body := &dataBlock.Body{
MiniBlocks: dataBlock.MiniBlockSlice{
{
Type: dataBlock.TxBlock,
SenderShardID: 2,
ReceiverShardID: 1,
TxHashes: [][]byte{txHash},
},
{
Type: dataBlock.SmartContractResultBlock,
SenderShardID: 2,
ReceiverShardID: 2,
TxHashes: [][]byte{scrHash1},
},
},
}

address1 := "erd1ef6470tjdtlgpa9f6g3ae4nsedmjg0gv6w73v32xtvhkfff993hq750xl9"
address2 := "erd13u7zyekzvdvzek8768r5gau9p6677ufppsjuklu9e6t7yx7rhg4s68e2ze"

txESDT := outport.TxInfo{
Transaction: &transaction.Transaction{
Nonce: 1,
SndAddr: decodeAddress(address1),
RcvAddr: decodeAddress(address2),
GasLimit: 500_000,
GasPrice: 1000000000,
Data: []byte("ESDTTransfer@54474e2d383862383366@0a"),
Value: big.NewInt(0),
},
FeeInfo: &outport.FeeInfo{
GasUsed: 334_000,
Fee: big.NewInt(136000000000000),
InitialPaidFee: big.NewInt(137660000000000),
},
}

refundValueBig, _ := big.NewInt(0).SetString("1660000000000", 10)
scrRefund := &smartContractResult.SmartContractResult{
Nonce: 20,
SndAddr: decodeAddress(address2),
RcvAddr: decodeAddress(address1),
PrevTxHash: txHash,
OriginalTxHash: txHash,
Value: refundValueBig,
Data: []byte("@6f6b"),
}

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
hex.EncodeToString(txHash): &txESDT,
},
SmartContractResults: map[string]*outport.SCRInfo{
hex.EncodeToString(scrHash1): {SmartContractResult: scrRefund, FeeInfo: &outport.FeeInfo{}},
},
}
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards))
require.Nil(t, err)

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

require.JSONEq(t, readExpectedResult("./testdata/esdtTransfer/esdt-transfer-cross-shard-on-source.json"), string(genericResponse.Docs[0].Source))

header = &dataBlock.Header{
Round: 55,
TimeStamp: 10102,
ShardID: 1,
}
txESDT.FeeInfo = &outport.FeeInfo{
GasUsed: 500_000,
Fee: big.NewInt(137660000000000),
InitialPaidFee: big.NewInt(137660000000000),
}

err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards))
require.Nil(t, err)

err = esClient.DoMultiGet(context.Background(), ids, indexerdata.OperationsIndex, true, genericResponse)
require.Nil(t, err)

require.JSONEq(t, readExpectedResult("./testdata/esdtTransfer/esdt-transfer-cross-shard-on-destination.json"), string(genericResponse.Docs[0].Source))
}

func TestESDTTransferCrossShardIndexFirstOnDestinationAndAfterSource(t *testing.T) {
esClient, err := createESClient(esURL)
require.Nil(t, err)

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

txHash := []byte("esdtTransferCross2")
header := &dataBlock.Header{
Round: 55,
TimeStamp: 10102,
ShardID: 1,
}

scrHash1 := []byte("scrHash1ESDTTransferOnSourceShard2")
body := &dataBlock.Body{
MiniBlocks: dataBlock.MiniBlockSlice{
{
Type: dataBlock.TxBlock,
SenderShardID: 2,
ReceiverShardID: 1,
TxHashes: [][]byte{txHash},
},
},
}

address1 := "erd1ef6470tjdtlgpa9f6g3ae4nsedmjg0gv6w73v32xtvhkfff993hq750xl9"
address2 := "erd13u7zyekzvdvzek8768r5gau9p6677ufppsjuklu9e6t7yx7rhg4s68e2ze"

txESDT := outport.TxInfo{
Transaction: &transaction.Transaction{
Nonce: 1,
SndAddr: decodeAddress(address1),
RcvAddr: decodeAddress(address2),
GasLimit: 500_000,
GasPrice: 1000000000,
Data: []byte("ESDTTransfer@54474e2d383862383366@0a"),
Value: big.NewInt(0),
},
FeeInfo: &outport.FeeInfo{
GasUsed: 500_000,
Fee: big.NewInt(137660000000000),
InitialPaidFee: big.NewInt(137660000000000),
},
}

refundValueBig, _ := big.NewInt(0).SetString("1660000000000", 10)
scrRefund := &smartContractResult.SmartContractResult{
Nonce: 20,
SndAddr: decodeAddress(address2),
RcvAddr: decodeAddress(address1),
PrevTxHash: txHash,
OriginalTxHash: txHash,
Value: refundValueBig,
Data: []byte("@6f6b"),
}

pool := &outport.TransactionPool{
Transactions: map[string]*outport.TxInfo{
hex.EncodeToString(txHash): &txESDT,
},
SmartContractResults: map[string]*outport.SCRInfo{
hex.EncodeToString(scrHash1): {SmartContractResult: scrRefund, FeeInfo: &outport.FeeInfo{}},
},
}
err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards))
require.Nil(t, err)

ids := []string{hex.EncodeToString(txHash)}
genericResponse := &GenericResponse{}
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.OperationsIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/esdtTransfer/esdt-transfer-first-on-destination.json"), string(genericResponse.Docs[0].Source))

txESDT.FeeInfo = &outport.FeeInfo{
GasUsed: 334_000,
Fee: big.NewInt(136000000000000),
InitialPaidFee: big.NewInt(137660000000000),
}
header = &dataBlock.Header{
Round: 50,
TimeStamp: 10101,
ShardID: 2,
}
body.MiniBlocks = append(body.MiniBlocks, &dataBlock.MiniBlock{
Type: dataBlock.SmartContractResultBlock,
SenderShardID: 2,
ReceiverShardID: 2,
TxHashes: [][]byte{scrHash1},
})

err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards))
require.Nil(t, err)

err = esClient.DoMultiGet(context.Background(), ids, indexerdata.OperationsIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/esdtTransfer/esdt-transfer-second-on-source.json"), string(genericResponse.Docs[0].Source))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"miniBlockHash": "579fe2f60e8fa9c396254b2173282c6ecb6e736b42e015c3b744c86001be3981",
"nonce": 1,
"round": 55,
"value": "0",
"valueNum": 0,
"receiver": "erd13u7zyekzvdvzek8768r5gau9p6677ufppsjuklu9e6t7yx7rhg4s68e2ze",
"sender": "erd1ef6470tjdtlgpa9f6g3ae4nsedmjg0gv6w73v32xtvhkfff993hq750xl9",
"receiverShard": 1,
"senderShard": 2,
"gasPrice": 1000000000,
"gasLimit": 500000,
"gasUsed": 334000,
"fee": "136000000000000",
"feeNum": 0.000136,
"initialPaidFee": "137660000000000",
"data": "RVNEVFRyYW5zZmVyQDU0NDc0ZTJkMzgzODYyMzgzMzY2QDBh",
"signature": "",
"timestamp": 10102,
"status": "success",
"searchOrder": 0,
"hasScResults": true,
"tokens": [
"TGN-88b83f"
],
"esdtValues": [
"10"
],
"esdtValuesNum": [
1e-17
],
"type": "normal",
"operation": "ESDTTransfer"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"miniBlockHash": "579fe2f60e8fa9c396254b2173282c6ecb6e736b42e015c3b744c86001be3981",
"nonce": 1,
"round": 50,
"value": "0",
"valueNum": 0,
"receiver": "erd13u7zyekzvdvzek8768r5gau9p6677ufppsjuklu9e6t7yx7rhg4s68e2ze",
"sender": "erd1ef6470tjdtlgpa9f6g3ae4nsedmjg0gv6w73v32xtvhkfff993hq750xl9",
"receiverShard": 1,
"senderShard": 2,
"gasPrice": 1000000000,
"gasLimit": 500000,
"gasUsed": 334000,
"fee": "136000000000000",
"feeNum": 0.000136,
"initialPaidFee": "137660000000000",
"data": "RVNEVFRyYW5zZmVyQDU0NDc0ZTJkMzgzODYyMzgzMzY2QDBh",
"signature": "",
"timestamp": 10101,
"status": "pending",
"searchOrder": 0,
"hasScResults": true,
"tokens": [
"TGN-88b83f"
],
"esdtValues": [
"10"
],
"esdtValuesNum": [
1e-17
],
"type": "normal",
"operation": "ESDTTransfer"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"data": "RVNEVFRyYW5zZmVyQDU0NDc0ZTJkMzgzODYyMzgzMzY2QDBh",
"signature": "",
"fee": "137660000000000",
"esdtValues": [
"10"
],
"initialPaidFee": "137660000000000",
"type": "normal",
"gasLimit": 500000,
"esdtValuesNum": [
1e-17
],
"gasUsed": 500000,
"miniBlockHash": "d0f273198e773465908be139872605d93e86115b6320f9b34edb6a5e38668989",
"senderShard": 2,
"tokens": [
"TGN-88b83f"
],
"value": "0",
"gasPrice": 1000000000,
"timestamp": 10102,
"receiver": "erd13u7zyekzvdvzek8768r5gau9p6677ufppsjuklu9e6t7yx7rhg4s68e2ze",
"valueNum": 0,
"feeNum": 0.00013766,
"nonce": 1,
"round": 55,
"hasScResults": true,
"sender": "erd1ef6470tjdtlgpa9f6g3ae4nsedmjg0gv6w73v32xtvhkfff993hq750xl9",
"receiverShard": 1,
"operation": "ESDTTransfer",
"status": "success",
"searchOrder": 0
}
Loading

0 comments on commit 7dc6e64

Please sign in to comment.