Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating new contracts #389

Merged
merged 12 commits into from
Dec 19, 2024
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
chain-simulator:
image: multiversx/chainsimulator:v1.7.13-patch2
image: multiversx/chainsimulator:v1.8.4-fix1
ports:
- 8085:8085
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
generateBlocksUntilTxProcessedEndpoint = "simulator/generate-blocks-until-transaction-processed/%s"
numProbeRetries = 10
networkConfigEndpointTemplate = "network/status/%d"
codeMetadata = "0502"
)

var (
Expand Down Expand Up @@ -129,7 +130,7 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
require.Nil(instance.TB, err)

scCode := wasm.GetSCCode(wasmFilePath)
params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex}
params := []string{scCode, wasm.VMTypeHex, codeMetadata}
params = append(params, parameters...)
txData := strings.Join(params, "@")

Expand Down
192 changes: 53 additions & 139 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ const (
bridgeProxyContractPath = "testdata/contracts/mvx/bridge-proxy.wasm"
testCallerContractPath = "testdata/contracts/mvx/test-caller.wasm"

setBridgeProxyContractAddressFunction = "setBridgeProxyContractAddress"
setWrappingContractAddressFunction = "setWrappingContractAddress"
changeOwnerAddressFunction = "ChangeOwnerAddress"
setEsdtSafeOnMultiTransferFunction = "setEsdtSafeOnMultiTransfer"
setEsdtSafeAddressFunction = "setEsdtSafeAddress"
moveRefundBatchToSafeFromChildContractFunction = "moveRefundBatchToSafeFromChildContract"
getCurrentRefundBatchFunction = "getCurrentRefundBatch"
stakeFunction = "stake"
Expand All @@ -71,8 +67,6 @@ const (
submitBatchFunction = "submitBatch"
unwrapTokenCreateTransactionFunction = "unwrapTokenCreateTransaction"
createTransactionFunction = "createTransaction"
setBridgedTokensWrapperAddressFunction = "setBridgedTokensWrapperAddress"
setMultiTransferAddressFunction = "setMultiTransferAddress"
withdrawRefundFeesForEthereumFunction = "withdrawRefundFeesForEthereum"
getRefundFeesForEthereumFunction = "getRefundFeesForEthereum"
withdrawTransactionFeesFunction = "withdrawTransactionFees"
Expand All @@ -82,6 +76,8 @@ const (
getMintBalances = "getMintBalances"
getBurnBalances = "getBurnBalances"
getTotalBalances = "getTotalBalances"
getRefundTransactions = "getRefundTransactions"
executeRefundTransaction = "executeRefundTransaction"
)

var (
Expand Down Expand Up @@ -137,10 +133,6 @@ func NewMultiversxHandler(
func (handler *MultiversxHandler) DeployAndSetContracts(ctx context.Context) {
handler.deployContracts(ctx)

handler.wireMultiTransfer(ctx)
handler.wireSCProxy(ctx)
handler.wireSafe(ctx)

handler.changeOwners(ctx)
handler.finishSettings(ctx)
}
Expand Down Expand Up @@ -200,8 +192,6 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
handler.OwnerKeys.MvxSk,
deployGasLimit,
[]string{
handler.AggregatorAddress.Hex(),
handler.MultiTransferAddress.Hex(),
"01",
},
)
Expand All @@ -214,9 +204,7 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
bridgeProxyContractPath,
handler.OwnerKeys.MvxSk,
deployGasLimit,
[]string{
handler.MultiTransferAddress.Hex(),
},
make([]string, 0),
)
require.NotEqual(handler, emptyAddress, handler.ScProxyAddress)
log.Info("Deploy: SC proxy contract", "address", handler.ScProxyAddress, "transaction hash", hash)
Expand All @@ -228,6 +216,8 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
handler.SafeAddress.Hex(),
handler.MultiTransferAddress.Hex(),
handler.ScProxyAddress.Hex(),
handler.WrapperAddress.Hex(),
handler.AggregatorAddress.Hex(),
minRelayerStakeHex,
slashAmount,
handler.Quorum}
Expand Down Expand Up @@ -256,117 +246,6 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
log.Info("Deploy: test-caller contract", "address", handler.CalleeScAddress, "transaction hash", hash)
}

func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) {
// setBridgeProxyContractAddress
params := []string{
handler.ScProxyAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultiTransferAddress,
zeroStringValue,
setCallsGasLimit,
setBridgeProxyContractAddressFunction,
params)

log.Info("Set in multi-transfer contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status)

// setWrappingContractAddress
params = []string{
handler.WrapperAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultiTransferAddress,
zeroStringValue,
setCallsGasLimit,
setWrappingContractAddressFunction,
params)

log.Info("Set in multi-transfer contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) {
// setBridgedTokensWrapper in SC bridge proxy
params := []string{
handler.WrapperAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setBridgedTokensWrapperAddressFunction,
params)

log.Info("Set in SC proxy contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)

// setMultiTransferAddress in SC bridge proxy
params = []string{
handler.MultiTransferAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setMultiTransferAddressFunction,
params)

log.Info("Set in SC proxy contract the multi-transfer contract", "transaction hash", hash, "status", txResult.Status)

// setEsdtSafeAddress on bridge proxy
params = []string{
handler.SafeAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setEsdtSafeAddressFunction,
params)

log.Info("Set in SC proxy contract the safe contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) wireSafe(ctx context.Context) {
// setBridgedTokensWrapperAddress
params := []string{
handler.WrapperAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.SafeAddress,
zeroStringValue,
setCallsGasLimit,
setBridgedTokensWrapperAddressFunction,
params)

log.Info("Set in safe contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)

//setBridgeProxyContractAddress
params = []string{
handler.ScProxyAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.SafeAddress,
zeroStringValue,
setCallsGasLimit,
setBridgeProxyContractAddressFunction,
params)

log.Info("Set in safe contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) changeOwners(ctx context.Context) {
// ChangeOwnerAddress for safe
params := []string{
Expand Down Expand Up @@ -419,18 +298,6 @@ func (handler *MultiversxHandler) finishSettings(ctx context.Context) {
hash, txResult := handler.callContractNoParams(ctx, handler.MultisigAddress, unpauseProxyFunction)
log.Info("Un-paused SC proxy contract", "transaction hash", hash, "status", txResult.Status)

// setEsdtSafeOnMultiTransfer
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultisigAddress,
zeroStringValue,
setCallsGasLimit,
setEsdtSafeOnMultiTransferFunction,
[]string{})

log.Info("Set in multisig contract the safe contract (automatically)", "transaction hash", hash, "status", txResult.Status)

// stake relayers on multisig
handler.stakeAddressesOnContract(ctx, handler.MultisigAddress, handler.RelayersKeys)

Expand Down Expand Up @@ -565,9 +432,9 @@ func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx c
return
}
handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params)
handler.transferChainSpecificTokenToSCs(ctx, params)
handler.addUniversalTokenToWrapper(ctx, params)
handler.whitelistTokenOnWrapper(ctx, params)
handler.transferChainSpecificTokenToSCs(ctx, params)
handler.setRolesForSpecificTokenOnSafe(ctx, params)
handler.addMappingInMultisig(ctx, params)
handler.whitelistTokenOnMultisig(ctx, params)
Expand Down Expand Up @@ -1239,6 +1106,53 @@ func (handler *MultiversxHandler) scCallAndCheckTx(
return hash, txResult
}

// RefundAllFromScBridgeProxy will refund transactions from the bridge proxy, if existing
func (handler *MultiversxHandler) RefundAllFromScBridgeProxy(ctx context.Context) {
refundIDs := handler.getAllRefundIDsFromScBridgeProxy(ctx)
if len(refundIDs) == 0 {
return
}

for _, refundID := range refundIDs {
handler.refundTransactionInScBridgeProxy(ctx, refundID)
}
}

func (handler *MultiversxHandler) getAllRefundIDsFromScBridgeProxy(ctx context.Context) []uint64 {
responseBytes := handler.ChainSimulator.ExecuteVMQuery(
ctx,
handler.ScProxyAddress,
getRefundTransactions,
make([]string, 0),
)

numResponseLines := len(responseBytes)
require.Equal(handler, 0, numResponseLines%2, "expected an even number on response")

refundIDs := make([]uint64, 0, numResponseLines/2)
for i := 0; i < numResponseLines; i += 2 {
refundID := big.NewInt(0).SetBytes(responseBytes[i])
refundIDs = append(refundIDs, refundID.Uint64())
}

return refundIDs
}

func (handler *MultiversxHandler) refundTransactionInScBridgeProxy(ctx context.Context, refundID uint64) {
log.Info("sending refund transaction in SC bridge proxy", "refund ID", refundID)
handler.scCallAndCheckTx(
ctx,
handler.SCExecutorKeys, // anyone can call this, for example, the sc executor
handler.ScProxyAddress,
"0",
generalSCCallGasLimit,
executeRefundTransaction,
[]string{
hex.EncodeToString(big.NewInt(0).SetUint64(refundID).Bytes()),
},
)
}

func getHexBool(input bool) string {
if input {
return hexTrue
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/relayers/slowTests/testFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (flow *testFlow) process() (finished bool) {
flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx)
}

//TODO: move this logic into the SC calls executor
flow.setup.MultiversxHandler.RefundAllFromScBridgeProxy(flow.setup.Ctx)

transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...)
if !flow.secondHalfBridgeDone && transferDoneForSecondHalf {
flow.secondHalfBridgeDone = true
Expand Down
Loading
Loading