-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into move-testdata
- Loading branch information
Showing
27 changed files
with
503 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package e2etests | ||
|
||
import ( | ||
"fmt" | ||
|
||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/zeta-chain/zetacore/e2e/contracts/testdapp" | ||
"github.com/zeta-chain/zetacore/e2e/runner" | ||
"github.com/zeta-chain/zetacore/e2e/utils" | ||
) | ||
|
||
// deployFunc is a function that deploys a contract | ||
type deployFunc func(r *runner.E2ERunner) (ethcommon.Address, error) | ||
|
||
// deployMap maps contract names to deploy functions | ||
var deployMap = map[string]deployFunc{ | ||
"testdapp_zevm": deployZEVMTestDApp, | ||
"testdapp_evm": deployEVMTestDApp, | ||
} | ||
|
||
// TestDeployContract deploys the specified contract | ||
func TestDeployContract(r *runner.E2ERunner, args []string) { | ||
availableContractNames := make([]string, 0, len(deployMap)) | ||
for contractName := range deployMap { | ||
availableContractNames = append(availableContractNames, contractName) | ||
} | ||
availableContractNamesMessage := fmt.Sprintf("Available contract names: %v", availableContractNames) | ||
|
||
if len(args) != 1 { | ||
panic( | ||
"TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage, | ||
) | ||
} | ||
contractName := args[0] | ||
|
||
deployFunc, ok := deployMap[contractName] | ||
if !ok { | ||
panic(fmt.Sprintf("Unknown contract name: %s, %s", contractName, availableContractNamesMessage)) | ||
} | ||
|
||
addr, err := deployFunc(r) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
r.Logger.Print("%s deployed at %s", contractName, addr.Hex()) | ||
} | ||
|
||
// deployZEVMTestDApp deploys the TestDApp contract on ZetaChain | ||
func deployZEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { | ||
addr, tx, _, err := testdapp.DeployTestDApp( | ||
r.ZEVMAuth, | ||
r.ZEVMClient, | ||
r.ConnectorZEVMAddr, | ||
r.WZetaAddr, | ||
) | ||
if err != nil { | ||
return addr, err | ||
} | ||
|
||
// Wait for the transaction to be mined | ||
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
if receipt.Status != 1 { | ||
return addr, fmt.Errorf("contract deployment failed") | ||
} | ||
|
||
return addr, nil | ||
} | ||
|
||
// deployEVMTestDApp deploys the TestDApp contract on Ethereum | ||
func deployEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { | ||
addr, tx, _, err := testdapp.DeployTestDApp( | ||
r.EVMAuth, | ||
r.EVMClient, | ||
r.ConnectorEthAddr, | ||
r.ZetaEthAddr, | ||
) | ||
if err != nil { | ||
return addr, err | ||
} | ||
|
||
// Wait for the transaction to be mined | ||
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
if receipt.Status != 1 { | ||
return addr, fmt.Errorf("contract deployment failed") | ||
} | ||
|
||
return addr, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/zetacore/x/crosschain/types" | ||
) | ||
|
||
// CCTXGatewayObservers is implementation of CCTXGateway interface for observers | ||
type CCTXGatewayObservers struct { | ||
crosschainKeeper Keeper | ||
} | ||
|
||
// NewCCTXGatewayObservers returns new instance of CCTXGatewayObservers | ||
func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { | ||
return CCTXGatewayObservers{ | ||
crosschainKeeper: crosschainKeeper, | ||
} | ||
} | ||
|
||
/* | ||
InitiateOutbound updates the store so observers can use the PendingCCTX query: | ||
- If preprocessing of outbound is successful, the CCTX status is changed to PendingOutbound. | ||
- if preprocessing of outbound, such as paying the gas fee for the destination fails, the state is reverted to aborted | ||
We do not return an error from this function, as all changes need to be persisted to the state. | ||
Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. | ||
New CCTX status after preprocessing is returned. | ||
*/ | ||
func (c CCTXGatewayObservers) InitiateOutbound( | ||
ctx sdk.Context, | ||
cctx *types.CrossChainTx, | ||
) (newCCTXStatus types.CctxStatus) { | ||
tmpCtx, commit := ctx.CacheContext() | ||
outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId | ||
err := func() error { | ||
err := c.crosschainKeeper.PayGasAndUpdateCctx( | ||
tmpCtx, | ||
outboundReceiverChainID, | ||
cctx, | ||
cctx.InboundParams.Amount, | ||
false, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return c.crosschainKeeper.UpdateNonce(tmpCtx, outboundReceiverChainID, cctx) | ||
}() | ||
if err != nil { | ||
// do not commit anything here as the CCTX should be aborted | ||
cctx.SetAbort(err.Error()) | ||
return types.CctxStatus_Aborted | ||
} | ||
commit() | ||
cctx.SetPendingOutbound("") | ||
return types.CctxStatus_PendingOutbound | ||
} |
Oops, something went wrong.