e2e_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package e2e
  2. import (
  3. "context"
  4. "os"
  5. "testing"
  6. "time"
  7. "github.com/ethereum/go-ethereum/accounts/abi/bind"
  8. "k8s.io/client-go/kubernetes"
  9. "github.com/certusone/wormhole/node/pkg/devnet"
  10. "github.com/ethereum/go-ethereum/ethclient"
  11. )
  12. // Run in a remote Tilt env:
  13. // ETH_RPC=http://<bind IP>:8545 CGO_ENABLED=0 go test ./... -v
  14. func setup(t *testing.T) (*kubernetes.Clientset, *ethclient.Client, *bind.TransactOpts) {
  15. // List of pods we need in a ready state before we can run tests.
  16. want := []string{
  17. // Our test guardian set.
  18. "guardian-0",
  19. //"guardian-1",
  20. //"guardian-2",
  21. //"guardian-3",
  22. //"guardian-4",
  23. //"guardian-5",
  24. // Connected chains
  25. "solana-devnet-0",
  26. "eth-devnet-0",
  27. }
  28. c := getk8sClient()
  29. // Wait for all pods to be ready. This blocks until the bridge is ready to receive lockups.
  30. ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
  31. defer cancel()
  32. waitForPods(ctx, c, want)
  33. if ctx.Err() != nil {
  34. t.Fatal(ctx.Err())
  35. }
  36. ethRPC := devnet.GanacheRPCURL
  37. if env := os.Getenv("ETH_RPC"); env != "" {
  38. ethRPC = env
  39. }
  40. // Ethereum client.
  41. ec, err := ethclient.Dial(ethRPC)
  42. if err != nil {
  43. t.Fatalf("dialing devnet eth rpc failed: %v", err)
  44. }
  45. kt := devnet.GetKeyedTransactor(context.Background())
  46. return c, ec, kt
  47. }
  48. // Careful about parallel tests - accounts on some chains like Ethereum cannot be
  49. // used concurrently as they have monotonically increasing nonces that would conflict.
  50. // Either use different Ethereum account, or do not run Ethereum tests in parallel.
  51. func TestEndToEnd_SOL_ETH(t *testing.T) {
  52. c, ec, kt := setup(t)
  53. t.Run("[SOL] Native -> [ETH] Wrapped", func(t *testing.T) {
  54. testSolanaLockup(t, context.Background(), ec, c,
  55. // Source SPL account
  56. devnet.SolanaExampleTokenOwningAccount,
  57. // Source SPL token
  58. devnet.SolanaExampleToken,
  59. // Our wrapped destination token on Ethereum
  60. devnet.GanacheExampleERC20WrappedSOL,
  61. // Amount of SPL token value to transfer.
  62. 50*devnet.SolanaDefaultPrecision,
  63. // Same precision - same amount, no precision gained.
  64. 0,
  65. )
  66. })
  67. t.Run("[ETH] Wrapped -> [SOL] Native", func(t *testing.T) {
  68. testEthereumLockup(t, context.Background(), ec, kt, c,
  69. // Source ERC20 token
  70. devnet.GanacheExampleERC20WrappedSOL,
  71. // Destination SPL token account
  72. devnet.SolanaExampleTokenOwningAccount,
  73. // Amount (the reverse of what the previous test did, with the same precision because
  74. // the wrapped ERC20 is set to the original asset's 10**9 precision).
  75. 50*devnet.SolanaDefaultPrecision,
  76. // No precision loss
  77. 0,
  78. )
  79. })
  80. t.Run("[ETH] Native -> [SOL] Wrapped", func(t *testing.T) {
  81. testEthereumLockup(t, context.Background(), ec, kt, c,
  82. // Source ERC20 token
  83. devnet.GanacheExampleERC20Token,
  84. // Destination SPL token account
  85. devnet.SolanaExampleWrappedERCTokenOwningAccount,
  86. // Amount
  87. 0.000000012*devnet.ERC20DefaultPrecision,
  88. // We lose 9 digits of precision on this path, as the default ERC20 token has 10**18 precision.
  89. 9,
  90. )
  91. })
  92. t.Run("[SOL] Wrapped -> [ETH] Native", func(t *testing.T) {
  93. testSolanaLockup(t, context.Background(), ec, c,
  94. // Source SPL account
  95. devnet.SolanaExampleWrappedERCTokenOwningAccount,
  96. // Source SPL token
  97. devnet.SolanaExampleWrappedERCToken,
  98. // Our wrapped destination token on Ethereum
  99. devnet.GanacheExampleERC20Token,
  100. // Amount of SPL token value to transfer.
  101. 0.000000012*devnet.SolanaDefaultPrecision,
  102. // We gain 9 digits of precision on Eth.
  103. 9,
  104. )
  105. })
  106. }