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

MVX-> ETH integration test swap with chain simulator #290

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this timer is only a fallback protection as the proxyInstance.ProcessTransactionStatus should always give a result.
However, the approach is a little bit misleading because it will block the tes forever if one transaction is failed. I will try to come up with a better solution to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as suggested

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
Loading