Skip to content

Commit

Permalink
updated tests to handle avalanche
Browse files Browse the repository at this point in the history
Signed-off-by: Soumya Ghosh Dastidar <[email protected]>
  • Loading branch information
gdsoumya committed Jun 23, 2021
1 parent 8cc7164 commit a02fc04
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions multichain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/renproject/multichain/chain/polygon"
"github.com/tyler-smith/go-bip39"
"io/ioutil"
"log"
"math/big"
"math/rand"
"os"
Expand Down Expand Up @@ -662,8 +661,6 @@ var _ = Describe("Multichain", func() {
client, err := avalanche.NewClient(string(rpcURL))
Expect(err).NotTo(HaveOccurred())
txBuilder := avalanche.NewTxBuilder(big.NewInt(43112))
x, y, z := avalanche.NewGasEstimator(client).EstimateGas(context.Background())
log.Print("gas: ", x, y, z)
return client, txBuilder
},
func(_ multichain.AccountClient) (pack.U256, pack.U256, pack.U256, pack.U256, pack.Bytes) {
Expand Down Expand Up @@ -866,47 +863,53 @@ var _ = Describe("Multichain", func() {
// Initialise the account chain's client, and possibly get a nonce for
// the sender.
accountClient, txBuilder := accountChain.initialise(accountChain.rpcURL)
sendTx := func() (pack.Bytes, pack.U256) {
// Get the appropriate nonce for sender.
nonce, err := accountClient.AccountNonce(ctx, senderAddr)
Expect(err).NotTo(HaveOccurred())

// Get the appropriate nonce for sender.
nonce, err := accountClient.AccountNonce(ctx, senderAddr)
Expect(err).NotTo(HaveOccurred())

// Build a transaction.
amount, gasLimit, gasPrice, gasCap, payload := accountChain.txParams(accountClient)

accountTx, err := txBuilder.BuildTx(
ctx,
multichain.Address(senderAddr),
recipientAddr,
amount, nonce, gasLimit, gasPrice, gasCap,
payload,
)
Expect(err).NotTo(HaveOccurred())
// Build a transaction.
amount, gasLimit, gasPrice, gasCap, payload := accountChain.txParams(accountClient)

// Get the transaction bytes and sign them.
sighashes, err := accountTx.Sighashes()
Expect(err).NotTo(HaveOccurred())
hash := id.Hash(sighashes[0])
sig, err := senderPrivKey.Sign(&hash)
Expect(err).NotTo(HaveOccurred())
sigBytes, err := surge.ToBinary(sig)
Expect(err).NotTo(HaveOccurred())
txSignature := pack.Bytes65{}
copy(txSignature[:], sigBytes)
senderPubKeyBytes, err := surge.ToBinary(senderPubKey)
Expect(err).NotTo(HaveOccurred())
err = accountTx.Sign(
[]pack.Bytes65{txSignature},
pack.NewBytes(senderPubKeyBytes),
)
Expect(err).NotTo(HaveOccurred())
accountTx, err := txBuilder.BuildTx(
ctx,
multichain.Address(senderAddr),
recipientAddr,
amount, nonce, gasLimit, gasPrice, gasCap,
payload,
)
Expect(err).NotTo(HaveOccurred())

// Submit the transaction to the account chain.
txHash := accountTx.Hash()
err = accountClient.SubmitTx(ctx, accountTx)
Expect(err).NotTo(HaveOccurred())
logger.Debug("submit tx", zap.String("from", string(senderAddr)), zap.String("to", string(recipientAddr)), zap.Any("txHash", txHash))
// Get the transaction bytes and sign them.
sighashes, err := accountTx.Sighashes()
Expect(err).NotTo(HaveOccurred())
hash := id.Hash(sighashes[0])
sig, err := senderPrivKey.Sign(&hash)
Expect(err).NotTo(HaveOccurred())
sigBytes, err := surge.ToBinary(sig)
Expect(err).NotTo(HaveOccurred())
txSignature := pack.Bytes65{}
copy(txSignature[:], sigBytes)
senderPubKeyBytes, err := surge.ToBinary(senderPubKey)
Expect(err).NotTo(HaveOccurred())
err = accountTx.Sign(
[]pack.Bytes65{txSignature},
pack.NewBytes(senderPubKeyBytes),
)
Expect(err).NotTo(HaveOccurred())

// Submit the transaction to the account chain.
txHash := accountTx.Hash()
err = accountClient.SubmitTx(ctx, accountTx)
Expect(err).NotTo(HaveOccurred())
logger.Debug("submit tx", zap.String("from", string(senderAddr)), zap.String("to", string(recipientAddr)), zap.Any("txHash", txHash))
return txHash, amount
}
txHash, amount := sendTx()
if accountChain.chain == multichain.Avalanche {
time.Sleep(5 * time.Second)
sendTx()
}
// Wait slightly before we query the chain's node.
time.Sleep(time.Second)

Expand Down

0 comments on commit a02fc04

Please sign in to comment.