Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
76 changes: 76 additions & 0 deletions .github/actions/go-setup-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'Go Setup Action'
description: 'Sets up Go environment with private modules support and caching'
inputs:
go-version:
description: 'The Go version to use'
required: false
default: '1.22.1'
go-private:
description: 'Private go modules'
required: false
default: 'github.com/klever-io/*'
cache-enabled:
description: 'Enable caching of Go modules'
required: false
default: 'true'
git-user:
description: 'Git username for private modules'
required: false
git-pass:
description: 'Git password or token for private modules'
required: false

runs:
using: "composite"
steps:
- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
cache: false

- name: Configure git for private modules
if: inputs.git-user != '' && inputs.git-pass != ''
shell: bash
run: |
git config --global url."https://${{ inputs.git-user }}:${{ inputs.git-pass }}@github.com".insteadOf "https://github.com"

- name: Cache Go dependencies
id: cache_vendor
if: inputs.cache-enabled == 'true'
uses: actions/cache@v4
env:
cache-name: go-cache-vendor
with:
path: |
~/go/pkg/mod
./vendor
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
enableCrossOsArchive: true

- name: Resolve package to module & Download dependencies
if: ${{ steps.cache_vendor.outputs.cache-hit != 'true' }}
shell: bash
run: |
go mod tidy
go mod download

- name: Generate Vendor and Install modvendor
if: ${{ steps.cache_vendor.outputs.cache-hit != 'true' }}
shell: bash
run: |
go install github.com/goware/modvendor@latest
go mod vendor
modvendor -copy="**/*.c **/*.h **/*.proto **/*.a"

- name: Verify no changes from go mod tidy
shell: bash
run: |
go mod tidy
if [ -n "$(git status --porcelain)" ]; then
echo "Changes found after go mod tidy:"
git status --porcelain
exit 1
fi
26 changes: 9 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@ on:

jobs:
build:
strategy:
matrix:
runs-on: [ ubuntu-latest ]
runs-on: ${{ matrix.runs-on }}
runs-on: ubuntu-latest
name: Build
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.20.7
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Go Setup
uses: ./.github/actions/go-setup-action
with:
go-version: ${{vars.GO_VERSION }}
go-private: ${{vars.GO_PRIVATE_REPO }}
git-user: ${{ secrets.GIT_USER }}
git-pass: ${{ secrets.GIT_PASS }}

- name: Build
run: |
cd ${GITHUB_WORKSPACE}/cmd/bridge && go build .
19 changes: 16 additions & 3 deletions executors/kleverBlockchain/module/scCallsModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (

"github.com/klever-io/klever-go/tools"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/interactors/nonceHandlerV2"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/mock"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy/models"
"github.com/klever-io/klv-bridge-eth-go/config"
kc "github.com/klever-io/klv-bridge-eth-go/executors/kleverBlockchain"
"github.com/klever-io/klv-bridge-eth-go/executors/kleverBlockchain/filters"
Expand Down Expand Up @@ -36,8 +37,20 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chClose
return nil, err
}

// TODO: change to real klever proxy when available
proxy := mock.CreateMockProxyKLV()
argsProxy := proxy.ArgsProxy{
ProxyURL: cfg.NetworkAddress,
SameScState: false,
ShouldBeSynced: false,
FinalityCheck: cfg.ProxyFinalityCheck,
AllowedDeltaToFinal: cfg.ProxyMaxNoncesDelta,
CacheExpirationTime: time.Second * time.Duration(cfg.ProxyCacherExpirationSeconds),
EntityType: models.RestAPIEntityType(cfg.ProxyRestAPIEntityType),
}

proxy, err := proxy.NewProxy(argsProxy)
if err != nil {
return nil, err
}

module := &scCallsModule{}

Expand Down
4 changes: 2 additions & 2 deletions executors/kleverBlockchain/scCallsExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (executor *scCallExecutor) checkResultsUntilDone(ctx context.Context, hash
}

func (executor *scCallExecutor) checkResults(ctx context.Context, hash string) (error, bool) {
txStatus, err := executor.proxy.ProcessTransactionStatus(ctx, hash)
txResult, err := executor.proxy.GetTransactionInfoWithResults(ctx, hash)
if err != nil {
if err.Error() == transactionNotFoundErrString {
return nil, false
Expand All @@ -421,7 +421,7 @@ func (executor *scCallExecutor) checkResults(ctx context.Context, hash string) (
return err, true
}

if txStatus == transaction.Transaction_SUCCESS {
if txResult.Status == transaction.Transaction_SUCCESS.String() {
return nil, true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import (
"github.com/klever-io/klever-go/data/transaction"
"github.com/klever-io/klever-go/tools"
"github.com/klever-io/klever-go/tools/marshal/factory"
"github.com/klever-io/klv-bridge-eth-go/clients/klever"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/blockchain/address"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/mock"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy/models"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/pubkeyConverter"
"github.com/multiversx/mx-chain-go/integrationTests/vm/wasm"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
sdkHttp "github.com/multiversx/mx-sdk-go/core/http"
"github.com/multiversx/mx-sdk-go/data"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -56,14 +54,23 @@ type ArgChainSimulatorWrapper struct {
type chainSimulatorWrapper struct {
testing.TB
clientWrapper httpClientWrapper
proxyInstance klever.Proxy
proxyInstance proxy.Proxy
pkConv core.PubkeyConverter
}

// CreateChainSimulatorWrapper creates a new instance of the chain simulator wrapper
func CreateChainSimulatorWrapper(args ArgChainSimulatorWrapper) *chainSimulatorWrapper {
// TODO: change this to use the real klever proxy when available
proxyInstance := mock.NewKCMock()
argsProxy := proxy.ArgsProxy{
ProxyURL: proxyURL,
SameScState: false,
ShouldBeSynced: false,
FinalityCheck: false,
AllowedDeltaToFinal: args.ProxyMaxNoncesDelta,
CacheExpirationTime: time.Second * time.Duration(args.ProxyCacherExpirationSeconds),
EntityType: models.Proxy,
}
proxyInstance, err := proxy.NewProxy(argsProxy)
require.Nil(args.TB, err)

pubKeyConverter, err := pubkeyConverter.NewBech32PubkeyConverter(32, "klv")
require.Nil(args.TB, err)
Expand Down Expand Up @@ -103,7 +110,7 @@ func (instance *chainSimulatorWrapper) probeURLWithRetries() {
}

// Proxy returns the managed proxy instance
func (instance *chainSimulatorWrapper) Proxy() klever.Proxy {
func (instance *chainSimulatorWrapper) Proxy() proxy.Proxy {
return instance.proxyInstance
}

Expand All @@ -113,7 +120,7 @@ func (instance *chainSimulatorWrapper) GetNetworkAddress() string {
}

// DeploySC will deploy the provided smart contract and return its address
func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePath string, ownerSK []byte, gasLimit uint64, parameters []string) (*KlvAddress, string, *data.TransactionOnNetwork) {
func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePath string, ownerSK []byte, gasLimit uint64, parameters []string) (*KlvAddress, string, *models.TransactionData) {
networkConfig, err := instance.proxyInstance.GetNetworkConfig(ctx)
require.Nil(instance.TB, err)

Expand All @@ -140,20 +147,17 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
}

// GetTransactionResult tries to get a transaction result. It may wait a few blocks
func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork {
func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) *models.TransactionData {
instance.GenerateBlocksUntilTxProcessed(ctx, hash)

txResult, err := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
require.Nil(instance, err)

txStatus, err := instance.proxyInstance.ProcessTransactionStatus(ctx, hash)
require.Nil(instance, err)

jsonData, err := json.MarshalIndent(txResult.Data.Transaction, "", " ")
jsonData, err := json.MarshalIndent(txResult.Status, "", " ")
require.Nil(instance, err)
require.Equal(instance, transaction.Transaction_SUCCESS, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData)))
require.Equal(instance, transaction.Transaction_SUCCESS, txResult.Status, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData)))

return &txResult.Data.Transaction
return txResult
}

// GenerateBlocks calls the chain simulator generate block endpoint
Expand Down Expand Up @@ -188,7 +192,7 @@ func (instance *chainSimulatorWrapper) GenerateBlocksUntilTxProcessed(ctx contex
}

// ScCall will make the provided sc call
func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *KlvAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork) {
func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *KlvAddress, value string, gasLimit uint64, function string, parameters []string) (string, *models.TransactionData) {
return instance.SendTx(ctx, senderSK, contract, value, gasLimit, createTxData(function, parameters))
}

Expand All @@ -206,7 +210,7 @@ func createTxData(function string, parameters []string) []byte {
}

// SendTx will build and send a transaction
func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *KlvAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork) {
func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *KlvAddress, value string, gasLimit uint64, dataField []byte) (string, *models.TransactionData) {
hash := instance.SendTxWithoutGenerateBlocks(ctx, senderSK, receiver, value, gasLimit, dataField)
instance.GenerateBlocks(ctx, 1)
txResult := instance.GetTransactionResult(ctx, hash)
Expand Down
14 changes: 7 additions & 7 deletions integrationTests/relayers/slowTests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/klever-io/klv-bridge-eth-go/clients/klever"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/blockchain/address"
"github.com/multiversx/mx-sdk-go/data"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy/models"
)

type httpClientWrapper interface {
Expand All @@ -29,19 +29,19 @@ type Relayer interface {

// ChainSimulatorWrapper defines the wrapper over the chain simulator
type ChainSimulatorWrapper interface {
Proxy() klever.Proxy
Proxy() proxy.Proxy
GetNetworkAddress() string
DeploySC(ctx context.Context, path string, ownerSK []byte, gasLimit uint64, extraParams []string) (*KlvAddress, string, *data.TransactionOnNetwork)
ScCall(ctx context.Context, senderSK []byte, contract *KlvAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork)
DeploySC(ctx context.Context, path string, ownerSK []byte, gasLimit uint64, extraParams []string) (*KlvAddress, string, *models.TransactionData)
ScCall(ctx context.Context, senderSK []byte, contract *KlvAddress, value string, gasLimit uint64, function string, parameters []string) (string, *models.TransactionData)
ScCallWithoutGenerateBlocks(ctx context.Context, senderSK []byte, contract *KlvAddress, value string, gasLimit uint64, function string, parameters []string) string
SendTx(ctx context.Context, senderSK []byte, receiver *KlvAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork)
SendTx(ctx context.Context, senderSK []byte, receiver *KlvAddress, value string, gasLimit uint64, dataField []byte) (string, *models.TransactionData)
SendTxWithoutGenerateBlocks(ctx context.Context, senderSK []byte, receiver *KlvAddress, value string, gasLimit uint64, dataField []byte) string
FundWallets(ctx context.Context, wallets []string)
GenerateBlocksUntilEpochReached(ctx context.Context, epoch uint32)
GenerateBlocks(ctx context.Context, numBlocks int)
GetKDABalance(ctx context.Context, address *KlvAddress, token string) string
GetBlockchainTimeStamp(ctx context.Context) uint64
GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork
GetTransactionResult(ctx context.Context, hash string) *models.TransactionData
ExecuteVMQuery(ctx context.Context, scAddress *KlvAddress, function string, hexParams []string) [][]byte
}

Expand Down
6 changes: 3 additions & 3 deletions integrationTests/relayers/slowTests/framework/kcHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/multiversx/mx-sdk-go/data"
"github.com/klever-io/klv-bridge-eth-go/clients/klever/proxy/models"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -478,7 +478,7 @@ func (handler *KCHandler) GetKDAChainSpecificTokenBalance(
return balance
}

func (handler *KCHandler) callContractNoParams(ctx context.Context, contract *KlvAddress, endpoint string) (string, *data.TransactionOnNetwork) {
func (handler *KCHandler) callContractNoParams(ctx context.Context, contract *KlvAddress, endpoint string) (string, *models.TransactionData) {
return handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.KlvSk,
Expand Down Expand Up @@ -873,7 +873,7 @@ func (handler *KCHandler) setMaxBridgeAmountOnMultitransfer(ctx context.Context,
log.Info("multi-transfer set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status)
}

func (handler *KCHandler) getTokenNameFromResult(txResult data.TransactionOnNetwork) string {
func (handler *KCHandler) getTokenNameFromResult(txResult models.TransactionData) string {
for _, event := range txResult.Logs.Events {
if event.Identifier == issueFunction {
require.Greater(handler, len(event.Topics), 1)
Expand Down