Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions .github/workflows/relayer-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ jobs:
- name: Run integration tests
run: |
pushd integration-tests
cp tracetracking/.env.example tracetracking/.env
nix develop -c go test -v -count=1 -p=1 -timeout 30m ./...
nix develop -c go test -v -count=1 -p=3 -timeout 30m ./...

build-pkgs:
name: Build and package (Nix and Docker)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/smartcontractkit/chain-selectors v1.0.60
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250527164052-5a4fb8e255ff
github.com/smartcontractkit/chainlink-deployments-framework v0.10.0
github.com/smartcontractkit/chainlink-testing-framework/framework v0.9.6
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.4-0.20250715093717-c04d8ef39fa3
github.com/smartcontractkit/chainlink-ton v0.0.0
github.com/smartcontractkit/freeport v0.1.0
github.com/stretchr/testify v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ github.com/smartcontractkit/chainlink-deployments-framework v0.10.0 h1:DTLUJsC66
github.com/smartcontractkit/chainlink-deployments-framework v0.10.0/go.mod h1:pe1X7qw2h+bYH90OheAlZ/vYCq8SKOnFAXGWUmIIeSc=
github.com/smartcontractkit/chainlink-testing-framework/framework v0.9.6 h1:vnUXO+Fhr7x30+ptRRv7/CqLwENnrWjZiLoTDYEw+iY=
github.com/smartcontractkit/chainlink-testing-framework/framework v0.9.6/go.mod h1:q99H9vcMJDs6T+zsSI8XJZd6PUkZnyG3iaRbrYNUCTk=
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.4-0.20250715093717-c04d8ef39fa3 h1:rZEHHWavONSmoeSaWpNPZNoihf/p395/oPYLfBd5HUQ=
github.com/smartcontractkit/chainlink-testing-framework/framework v0.10.4-0.20250715093717-c04d8ef39fa3/go.mod h1:47sm4C5wBxR8VBAZoDRGSt5wJwDJN3vVeE36l5vQs1g=
github.com/smartcontractkit/freeport v0.1.0 h1:3MZHeti5m+tSTBCq5R8rhawFHxrnQZYBZVL+xgS1sPo=
github.com/smartcontractkit/freeport v0.1.0/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/tracetracking/.env.example

This file was deleted.

294 changes: 146 additions & 148 deletions integration-tests/tracetracking/integration_test.go

Large diffs are not rendered by default.

74 changes: 12 additions & 62 deletions integration-tests/tracetracking/testutils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import (
"errors"
"fmt"
"math/big"
"os"
"path"
"strings"
"testing"

testutils "integration-tests/utils"

"github.com/joho/godotenv"
"github.com/stretchr/testify/require"

"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/tlb"
ton "github.com/xssnick/tonutils-go/ton"
wallet "github.com/xssnick/tonutils-go/ton/wallet"
Expand All @@ -25,19 +22,21 @@ import (
func SetUpTest(t *testing.T, chainID uint64, initialAmount *big.Int, fundedAccountsCount uint) (accounts []tracetracking.SignedAPIClient) {
api := testutils.CreateAPIClient(t, chainID)

// Get wallet for operations
funderWallet := getWallet(t, api)

// Run the spec tests, which are fully chain agnostic
funder := tracetracking.NewSignedAPIClient(api, *funderWallet)
accounts = make([]tracetracking.SignedAPIClient, fundedAccountsCount)

initialCoinAmount := tlb.FromNanoTON(initialAmount)
recipients := make([]*address.Address, fundedAccountsCount)
amounts := make([]tlb.Coins, fundedAccountsCount)

accounts = make([]tracetracking.SignedAPIClient, fundedAccountsCount)
for i := range fundedAccountsCount {
accounts[i] = createAndFundWallet(t, api, funder, initialCoinAmount)
w := testutils.CreateTonWallet(t, api, wallet.V3R2, wallet.WithWorkchain(0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
w := testutils.CreateTonWallet(t, api, wallet.V3R2, wallet.WithWorkchain(0))
w := testutils.CreateRandomTonWallet(t, api, wallet.V3R2, wallet.WithWorkchain(0))

recipients[i] = w.Address()
amounts[i] = tlb.FromNanoTON(initialAmount)

accounts[i] = tracetracking.NewSignedAPIClient(api, *w)
}

testutils.FundTonWallets(t, api, recipients, amounts)

return accounts
}

Expand All @@ -54,18 +53,6 @@ func GetRandomWallet(client ton.APIClientWrapped, version wallet.Version, option
return pw, nil
}

func createAndFundWallet(t *testing.T, api *ton.APIClient, funder tracetracking.SignedAPIClient, initialCoinAmount tlb.Coins) tracetracking.SignedAPIClient {
aliceWallet, err := GetRandomWallet(api, wallet.V3R2, wallet.WithWorkchain(0))
require.NoError(t, err, "failed to create new wallet: %w", err)
transferToAlice, err := funder.Wallet.BuildTransfer(aliceWallet.WalletAddress(), initialCoinAmount, false, "deposit")
require.NoError(t, err, "failed to build transfer: %w", err)
result, err := funder.SendAndWaitForTrace(context.TODO(), *aliceWallet.WalletAddress(), transferToAlice)
require.NoError(t, err, "failed to send transaction: %w", err)
require.True(t, result.Success && !result.Bounced, "Transaction failed")
alice := tracetracking.NewSignedAPIClient(api, *aliceWallet)
return alice
}

func GetWalletSeqno(apiClient tracetracking.SignedAPIClient) (uint, error) {
return UintFrom(Get(apiClient, "seqno"))
}
Expand All @@ -92,43 +79,6 @@ func UintFrom(res *ton.ExecutionResult, err error) (uint, error) {
return uint(val.Int64()), nil //nolint:gosec // test purpose
}

func getWallet(t *testing.T, api ton.APIClientWrapped) *wallet.Wallet {
// Load .env file from the project root
repoRoot := testutils.GetRepoRootDir()
err := godotenv.Load(path.Join(repoRoot, "integration-tests/tracetracking/.env"))
if err != nil {
// It's okay if the .env file doesn't exist in some environments
// so we'll just log it instead of failing
t.Logf("Warning: Error loading .env file: %s", err)
}
// Get seed phrase from environment variable
seedPhrase := os.Getenv("SIGNER_WALLET_SEED_PHRASE")
require.NotEmpty(t, seedPhrase, "Environment variable SIGNER_WALLET_SEED_PHRASE not set or empty")

words := strings.Fields(seedPhrase)

// Create wallet from seed with password
w, err := wallet.FromSeed(api, words, wallet.V3R2)
require.NoError(t, err, "failed to create wallet from seed: %w", err)

baseFunderWallet, err := wallet.FromPrivateKeyWithOptions(api, w.PrivateKey(), wallet.V3R2, wallet.WithWorkchain(-1))
require.NoError(t, err, "failed to create base funder wallet: %w", err)

//TODO: This is hardcoded for MyLocalTon pre-funded wallet
funderWallet, err := baseFunderWallet.GetSubwallet(42)
require.NoError(t, err, "failed to get subwallet: %w", err)
t.Logf("Funder wallet address: %s", funderWallet.WalletAddress().StringRaw())

// Check Funder Balance
masterInfo, err := api.GetMasterchainInfo(context.Background())
require.NoError(t, err, "failed to get masterchain info for funder balance check: %w", err)
funderBalance, err := funderWallet.GetBalance(context.Background(), masterInfo)
require.NoError(t, err, "failed to get funder balance: %w", err)
t.Logf("Funder balance: %s", funderBalance.String())

return funderWallet
}

// returns balance of the account in nanotons
func GetBalance(apiClient tracetracking.SignedAPIClient) (*big.Int, error) {
ctx := apiClient.Client.Client().StickyContext(context.Background())
Expand All @@ -151,7 +101,7 @@ func GetBalance(apiClient tracetracking.SignedAPIClient) (*big.Int, error) {

func VerifyTransaction(t *testing.T, m *tracetracking.ReceivedMessage, initialBalance *big.Int, expectedNetTransfer *big.Int, finalBalance *big.Int) {
expectedBalance := big.NewInt(0).Sub(tracetracking.Sum(initialBalance, m.NetCreditResult()), tracetracking.Sum(m.StorageFeeCharged, m.TotalTransactionExecutionFee()))
fmt.Printf(`================
t.Logf(`================
Transaction summary
────────────────────────────────────
Fees:
Expand Down
9 changes: 6 additions & 3 deletions integration-tests/utils/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,19 @@ func CreateAPIClient(t *testing.T, chainID uint64) *ton.APIClient {
bcInput := &blockchain.Input{
ChainID: strconv.FormatUint(chainID, 10),
Type: "ton",
Image: "ghcr.io/neodix42/mylocalton-docker:latest",
Port: strconv.Itoa(port),
CustomEnv: map[string]string{
"VERSION_CAPABILITIES": "11",
"NEXT_BLOCK_GENERATION_DELAY": "0.5",
},
}

bcOut, err := blockchain.NewBlockchainNetwork(bcInput)
require.NoError(t, err, "failed to create blockchain network")

t.Cleanup(func() {
ctfErr := framework.RemoveTestContainers()
require.NoError(t, ctfErr, "failed to remove test containers")
rterr := framework.RemoveTestContainers()
require.NoError(t, rterr, "failed to remove test containers")
freeport.Return([]int{port})
})

Expand Down
Loading