Skip to content

Commit

Permalink
Terra integration added to e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ysavchenko authored and leoluk committed Jan 19, 2021
1 parent eb9c4f2 commit eeb560c
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 12 deletions.
2 changes: 2 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ After a few seconds, the SPL token balance shown below will increase as the VAA
| `3C3m4tjTy4nSMkkYdqCDSiCWEgpDa6whvprvABdFGBiW` | Account that holds 6qRhs8oA... SPL tokens |
| `85kW19uNvETzH43p3AfpyqPaQS5rWouq4x9rGiKUvihf` | Wrapped token for the 0xCfEB86... ERC20 token |
| `7EFk3VrWeb29SWJPQs5cUyqcY3fQd33S9gELkGybRzeu` | Account that holds 85kW19u... wrapped tokens [2] |
| `9ESkHLgJH4zqbG7fvhpC9u2ZeHMoLJznCHtaRLviEVRh` | Wrapped token for the terra18vd8f... CW20 token |
| `EERzaqe8Agm8p1ZkGQFq9zKpP7MDW29FX1pC1vEw9Yfv` | Account that holds 9ESkHLg... wrapped tokens |

[1]: The account will eventually run out of funds if you run the lockup sending scripts for a long time. Refill it
using `kubectl exec solana-devnet-0 -c setup cli airdrop solana-devnet:9900` (see [devnet_setup.sh](solana/devnet_setup.sh)).
Expand Down
34 changes: 32 additions & 2 deletions bridge/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/ethclient"

"github.com/certusone/wormhole/bridge/pkg/devnet"
"github.com/ethereum/go-ethereum/ethclient"
)

func TestEndToEnd(t *testing.T) {
Expand Down Expand Up @@ -47,6 +46,12 @@ func TestEndToEnd(t *testing.T) {
}
kt := devnet.GetKeyedTransactor(ctx)

// Terra client
tc, err := NewTerraClient()
if err != nil {
t.Fatalf("creating devnet terra client failed: %v", err)
}

// Generic context for tests.
ctx, cancel = context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -107,4 +112,29 @@ func TestEndToEnd(t *testing.T) {
9,
)
})

t.Run("[Terra] Native -> [SOL] Wrapped", func(t *testing.T) {
testTerraLockup(t, ctx, tc, c,
// Source CW20 token
devnet.TerraTokenAddress,
// Destination SPL token account
devnet.SolanaExampleWrappedCWTokenOwningAccount,
// Amount
2*devnet.TerraDefaultPrecision,
// Same precision - same amount, no precision gained.
0,
)
})
t.Run("[SOL] Native -> [Terra] Wrapped", func(t *testing.T) {
testSolanaToTerraLockup(t, ctx, tc, c,
// Source SPL account
devnet.SolanaExampleTokenOwningAccount,
// Source SPL token
devnet.SolanaExampleToken,
// Amount of SPL token value to transfer.
50*devnet.SolanaDefaultPrecision,
// Same precision - same amount, no precision gained.
0,
)
})
}
52 changes: 52 additions & 0 deletions bridge/e2e/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/mr-tron/base58"
"github.com/tendermint/tendermint/libs/rand"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -116,3 +117,54 @@ func testSolanaLockup(t *testing.T, ctx context.Context, ec *ethclient.Client, c
// Source account decreases by full amount.
waitSPLBalance(t, ctx, c, sourceAcct, beforeSPL, -int64(amount))
}

func testSolanaToTerraLockup(t *testing.T, ctx context.Context, tc *TerraClient, c *kubernetes.Clientset,
sourceAcct string, tokenAddr string, amount int, precisionGain int) {

tokenSlice, err := base58.Decode(tokenAddr)
if err != nil {
t.Fatal(err)
}
terraToken, err := getAssetAddress(ctx, devnet.TerraBridgeAddress, vaa.ChainIDSolana, tokenSlice)

// Get balance if deployed
beforeCw20, err := getTerraBalance(ctx, terraToken)
if err != nil {
t.Log(err) // account may not yet exist, defaults to 0
}
t.Logf("CW20 balance: %v", beforeCw20)

// Store balance of source SPL token
beforeSPL, err := getSPLBalance(ctx, c, sourceAcct)
if err != nil {
t.Fatal(err)
}
t.Logf("SPL balance: %d", beforeSPL)

_, err = executeCommandInPod(ctx, c, "solana-devnet-0", "setup",
[]string{"cli", "lock",
// Address of the Wormhole bridge.
devnet.SolanaBridgeContract,
// Account which holds the SPL tokens to be sent.
sourceAcct,
// The SPL token.
tokenAddr,
// Token amount.
strconv.Itoa(amount),
// Destination chain ID.
strconv.Itoa(vaa.ChainIDTerra),
// Random nonce.
strconv.Itoa(int(rand.Uint16())),
// Destination account on Terra
devnet.TerraMainTestAddressHex,
})
if err != nil {
t.Fatal(err)
}

// Source account decreases by full amount.
waitSPLBalance(t, ctx, c, sourceAcct, beforeSPL, -int64(amount))

// Destination account increases by the full amount.
waitTerraUnknownBalance(t, ctx, devnet.TerraBridgeAddress, vaa.ChainIDSolana, tokenSlice, beforeCw20, int64(float64(amount)*math.Pow10(precisionGain)))
}
Loading

0 comments on commit eeb560c

Please sign in to comment.