Skip to content

Commit

Permalink
Merge pull request #290 from multiversx/mvx_to_eth
Browse files Browse the repository at this point in the history
MVX-> ETH integration test swap with chain simulator
  • Loading branch information
dragos-rebegea authored Mar 11, 2024
2 parents 520463b + 82090d2 commit 6b4b651
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 46 deletions.
1 change: 1 addition & 0 deletions clients/multiversx/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Proxy interface {
GetShardOfAddress(ctx context.Context, bech32Address string) (uint32, error)
GetESDTTokenData(ctx context.Context, address core.AddressHandler, tokenIdentifier string, queryOptions api.AccountQueryOptions) (*data.ESDTFungibleTokenData, error)
GetTransactionInfoWithResults(ctx context.Context, hash string) (*data.TransactionInfo, error)
ProcessTransactionStatus(ctx context.Context, hexTxHash string) (transaction.TxStatus, error)
IsInterfaceNil() bool
}

Expand Down
5 changes: 5 additions & 0 deletions integrationTests/mock/multiversXChainMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (mock *MultiversXChainMock) GetTransactionInfoWithResults(_ context.Context
return &data.TransactionInfo{}, nil
}

// ProcessTransactionStatus -
func (mock *MultiversXChainMock) ProcessTransactionStatus(_ context.Context, _ string) (transaction.TxStatus, error) {
return "", nil
}

// AddRelayer -
func (mock *MultiversXChainMock) AddRelayer(address sdkCore.AddressHandler) {
mock.mutState.Lock()
Expand Down
40 changes: 33 additions & 7 deletions integrationTests/proxyWithChainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,52 @@ func (instance *proxyWithChainSimulator) DeploySC(ctx context.Context, wasmFileP

// GetTransactionResult tries to get a transaction result. It may wait a few blocks
func (instance *proxyWithChainSimulator) GetTransactionResult(ctx context.Context, hash string) (data.TransactionOnNetwork, error) {
txResult, errGet := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
if errGet == nil && txResult.Data.Transaction.Status == transaction.TxStatusSuccess.String() {
return txResult.Data.Transaction, nil
txResult, err := instance.getTxInfoWithResultsIfTxProcessingFinished(ctx, hash)
if err == nil && txResult != nil {
return *txResult, nil
}

// wait for tx to be done, in order to get the contract address
timeoutTimer := time.NewTimer(instance.roundDuration * 5)
timeoutTimer := time.NewTimer(instance.roundDuration * 20)
for {
select {
case <-time.After(instance.roundDuration):
txResult, errGet = instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
if errGet == nil && txResult.Data.Transaction.Status == transaction.TxStatusSuccess.String() {
return txResult.Data.Transaction, nil
txResult, err = instance.getTxInfoWithResultsIfTxProcessingFinished(ctx, hash)
if err == nil && txResult != nil {
return *txResult, nil
}
if err != nil {
return data.TransactionOnNetwork{}, err
}
case <-timeoutTimer.C:
return data.TransactionOnNetwork{}, errors.New("timeout")
}
}
}

func (instance *proxyWithChainSimulator) getTxInfoWithResultsIfTxProcessingFinished(ctx context.Context, hash string) (*data.TransactionOnNetwork, error) {
txStatus, err := instance.proxyInstance.ProcessTransactionStatus(ctx, hash)
if err != nil {
return nil, err
}

if txStatus == transaction.TxStatusPending {
return nil, nil
}

if txStatus != transaction.TxStatusSuccess {
log.Warn("something went wrong with the transaction", "hash", hash, "status", txStatus)
}

txResult, errGet := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash)
if errGet != nil {
return nil, err
}

return &txResult.Data.Transaction, nil

}

// ScCall will make the provided sc call
func (instance *proxyWithChainSimulator) ScCall(ctx context.Context, senderPK string, senderSK []byte, contract string, value string, function string, parameters []string) (string, error) {
params := []string{function}
Expand Down
Loading

0 comments on commit 6b4b651

Please sign in to comment.