Skip to content

Commit

Permalink
integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Jan 25, 2024
1 parent 7fc6b07 commit 97af358
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 265 deletions.
2 changes: 1 addition & 1 deletion circle/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func CheckAttestation(attestationURL string, logger log.Logger, irisLookupId str
return nil
}
if rawResponse.StatusCode != http.StatusOK {
logger.Debug("non 200 response received")
logger.Debug("non 200 response received from Circles attestation API")
return nil
}
body, err := io.ReadAll(rawResponse.Body)
Expand Down
2 changes: 1 addition & 1 deletion ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ MsgLoop:
for _, msg := range msgs {

if msg.Status == types.Complete {
continue
continue MsgLoop
}

attestationBytes, err := hex.DecodeString(msg.Attestation[2:])
Expand Down
88 changes: 54 additions & 34 deletions integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,93 @@ import (
"cosmossdk.io/log"
"github.com/rs/zerolog"
"github.com/strangelove-ventures/noble-cctp-relayer/cmd"
"github.com/strangelove-ventures/noble-cctp-relayer/cmd/noble"
"github.com/strangelove-ventures/noble-cctp-relayer/ethereum"
"github.com/strangelove-ventures/noble-cctp-relayer/noble"
"github.com/strangelove-ventures/noble-cctp-relayer/types"

"gopkg.in/yaml.v3"
)

var testCfg *types.Config // for testing secrets
var cfg *types.Config // app config
var cfg *types.Config // app config
var integrationWallets *IntegrationWallets // for testing secrets

var nobleCfg *noble.ChainConfig
var ethCfg *ethereum.ChainConfig

var logger log.Logger
var err error

// goerli
const TokenMessengerAddress = "0xd0c3da58f55358142b8d3e06c1c30c5c6114efe8"
const TokenMessengerWithMetadataAddress = "0x1ae045d99236365cbdc1855acd2d2cfc232d04d1"
const UsdcAddress = "0x07865c6e87b9f70255377e024ace6630c1eaa37f"
var nobleChain types.Chain
var ethChain types.Chain

// Sepolia
const TokenMessengerAddress = "0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5"
const UsdcAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"

var sequenceMap *types.SequenceMap

func setupTest() func() {
// setup
testCfg, err = cmd.Parse("../.ignore/integration.yaml")
cfg, err = cmd.Parse("../.ignore/testnet.yaml")
func setupTestIntegration() func() {
logger = log.NewLogger(os.Stdout, log.LevelOption(zerolog.DebugLevel))

_, nextMinterSequence, err := noble.GetNobleAccountNumberSequence(
cfg.Networks.Destination.Noble.API,
cfg.Networks.Minters[4].MinterAddress)
// cctp relayer app config setup for sepolia netowrk
cfg, err = cmd.Parse("../.ignore/testnet.yaml")
if err != nil {
logger.Error("Error parsing relayer config")
os.Exit(1)
}

// extra wallets to keep relayer wallet separate from test transaction
// see config/sample-integration-config.yaml
err = ParseIntegration("../.ignore/integration.yaml")
if err != nil {
logger.Error("Error retrieving account sequence")
logger.Error("Error parsing integration wallets")
os.Exit(1)
}

nobleCfg = cfg.Chains["noble"].(*noble.ChainConfig)
ethCfg = cfg.Chains["ethereum"].(*ethereum.ChainConfig)

sequenceMap = types.NewSequenceMap()
sequenceMap.Put(uint32(4), nextMinterSequence)

for i, minter := range cfg.Networks.Minters {
switch i {
case 0:
minter.MinterAddress = "0x971c54a6Eb782fAccD00bc3Ed5E934Cc5bD8e3Ef"
cfg.Networks.Minters[0] = minter
case 4:
minter.MinterAddress = "noble1ar2gaqww6aphxd9qve5qglj8kqq96je6a4yrhj"
cfg.Networks.Minters[4] = minter
}

nobleChain, err = nobleCfg.Chain("noble")
if err != nil {
logger.Error("Error creating new chain", "err", err)
os.Exit(1)
}

ethChain, err = ethCfg.Chain("eth")
if err != nil {
logger.Error("Error creating new chain", "err", err)
os.Exit(1)
}

return func() {
// teardown
}
}

type Config struct {
// Wallets used for integration testing
type IntegrationWallets struct {
Networks struct {
Ethereum struct {
RPC string `yaml:"rpc"`
Address string `yaml:"address"`
PrivateKey string `yaml:"private_key"`
} `yaml:"ethereum"`
Noble struct {
RPC string `yaml:"rpc"`
Address string `yaml:"address"`
PrivateKey string `yaml:"private_key"`
} `yaml:"noble"`
} `yaml:"networks"`
}

func Parse(file string) (cfg Config) {
data, _ := os.ReadFile(file)
_ = yaml.Unmarshal(data, &cfg)
func ParseIntegration(file string) (err error) {
data, err := os.ReadFile(file)
if err != nil {
return err
}
err = yaml.Unmarshal(data, &integrationWallets)
if err != nil {
return err
}

return
return nil
}
103 changes: 0 additions & 103 deletions integration/eth_burn_to_noble_mint_and_forward_test.go

This file was deleted.

59 changes: 38 additions & 21 deletions integration/eth_burn_to_noble_mint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,66 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/strangelove-ventures/noble-cctp-relayer/cmd"
eth "github.com/strangelove-ventures/noble-cctp-relayer/cmd/ethereum"
"github.com/strangelove-ventures/noble-cctp-relayer/cosmos"
"github.com/strangelove-ventures/noble-cctp-relayer/ethereum/contracts"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
"github.com/stretchr/testify/require"
)

const uusdcDenom = "uusdc"

// TestEthBurnToNobleMint generates a depositForBurn on Ethereum Goerli and mints on Noble
func TestEthBurnToNobleMint(t *testing.T) {
setupTest()
ctx := context.Background()
setupTestIntegration()

fmt.Println("Starting relayer...")
processingQueue := make(chan *types.TxState, 10)

p := cmd.NewProcessor()
registeredDomains := make(map[types.Domain]types.Chain)
registeredDomains[0] = ethChain
registeredDomains[4] = nobleChain

// start up relayer
cfg.Networks.Source.Ethereum.StartBlock = getEthereumLatestBlockHeight(t)
cfg.Networks.Source.Ethereum.LookbackPeriod = 0
nobleChain.InitializeBroadcaster(ctx, logger, sequenceMap)

fmt.Println("Starting relayer...")
processingQueue := make(chan *types.MessageState, 10)
go eth.StartListener(cfg, logger, processingQueue)
go p.StartProcessor(context.TODO(), cfg, logger, processingQueue, sequenceMap)
go ethChain.StartListener(ctx, logger, processingQueue)
go cmd.StartProcessor(ctx, cfg, logger, registeredDomains, processingQueue, sequenceMap)

fmt.Println("Building Ethereum depositForBurnWithMetadata txn...")
fmt.Println("Building Ethereum depositForBurn txn...")
_, _, cosmosAddress := testdata.KeyTestPubAddr()
nobleAddress, _ := bech32.ConvertAndEncode("noble", cosmosAddress)
fmt.Println("Minting on Noble to https://testnet.mintscan.io/noble-testnet/account/" + nobleAddress)

// verify noble usdc amount
originalNobleBalance := getNobleBalance(nobleAddress)
cc, err := cosmos.NewProvider(nobleCfg.RPC)
require.Nil(t, err)
// originalNobleBalance := getNobleBalance(nobleAddress)
originalNobleBalance, err := getNobleAccountBalance(ctx, cc, nobleAddress, uusdcDenom)
require.NoError(t, err)

// deposit for burn with metadata
client, err := ethclient.Dial(testCfg.Networks.Ethereum.RPC)
client, err := ethclient.Dial(ethCfg.RPC)
require.Nil(t, err)
defer client.Close()

privateKey, err := crypto.HexToECDSA(testCfg.Networks.Ethereum.PrivateKey)
privateKey, err := crypto.HexToECDSA(integrationWallets.Networks.Ethereum.PrivateKey)

require.Nil(t, err)
auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(5))

sepoliaChainID := big.NewInt(ethCfg.ChainID)
auth, err := bind.NewKeyedTransactorWithChainID(privateKey, sepoliaChainID)
require.Nil(t, err)

tokenMessenger, err := cmd.NewTokenMessenger(common.HexToAddress(TokenMessengerAddress), client)
tokenMessenger, err := contracts.NewTokenMessenger(common.HexToAddress(TokenMessengerAddress), client)
require.Nil(t, err)

mintRecipientPadded := append([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, cosmosAddress...)
require.Nil(t, err)

erc20, err := NewERC20(common.HexToAddress(UsdcAddress), client)
_, err = erc20.Approve(auth, common.HexToAddress(TokenMessengerWithMetadataAddress), big.NewInt(99999))
require.NoError(t, err)

_, err = erc20.Approve(auth, common.HexToAddress(TokenMessengerAddress), big.NewInt(99999))
require.Nil(t, err)

var burnAmount = big.NewInt(1)
Expand All @@ -72,20 +86,23 @@ func TestEthBurnToNobleMint(t *testing.T) {
common.HexToAddress(UsdcAddress),
)
if err != nil {
logger.Error("Failed to update value: %v", err)
logger.Error("Failed to update value", "err", err)
}

time.Sleep(5 * time.Second)
fmt.Printf("Update pending: https://goerli.etherscan.io/tx/%s\n", tx.Hash().String())
fmt.Printf("Update pending: https://sepolia.etherscan.io/tx/%s\n", tx.Hash().String())

var newBalance uint64
fmt.Println("Checking noble wallet...")
for i := 0; i < 250; i++ {
if originalNobleBalance+burnAmount.Uint64() == getNobleBalance(nobleAddress) {
newBalance, err = getNobleAccountBalance(ctx, cc, nobleAddress, uusdcDenom)
require.NoError(t, err)
if originalNobleBalance+burnAmount.Uint64() == newBalance {
fmt.Println("Successfully minted at https://testnet.mintscan.io/noble-testnet/account/" + nobleAddress)
return
}
time.Sleep(1 * time.Second)
}
// verify noble balance
require.Equal(t, originalNobleBalance+burnAmount.Uint64(), getNobleBalance(nobleAddress))
require.Equal(t, originalNobleBalance+burnAmount.Uint64(), newBalance)
}
File renamed without changes.
Loading

0 comments on commit 97af358

Please sign in to comment.