-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/relayedv3' into MX-16207-mempool-chain-simulator
- Loading branch information
Showing
75 changed files
with
2,374 additions
and
457 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package common | ||
|
||
import "github.com/multiversx/mx-chain-core-go/data" | ||
|
||
// IsValidRelayedTxV3 returns true if the provided transaction is a valid transaction of type relayed v3 | ||
func IsValidRelayedTxV3(tx data.TransactionHandler) bool { | ||
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler) | ||
if !isRelayedV3 { | ||
return false | ||
} | ||
hasValidRelayer := len(relayedTx.GetRelayerAddr()) == len(tx.GetSndAddr()) && len(relayedTx.GetRelayerAddr()) > 0 | ||
hasValidRelayerSignature := len(relayedTx.GetRelayerSignature()) == len(relayedTx.GetSignature()) && len(relayedTx.GetRelayerSignature()) > 0 | ||
return hasValidRelayer && hasValidRelayerSignature | ||
} | ||
|
||
// IsRelayedTxV3 returns true if the provided transaction is a transaction of type relayed v3, without any further checks | ||
func IsRelayedTxV3(tx data.TransactionHandler) bool { | ||
relayedTx, isRelayedV3 := tx.(data.RelayedTransactionHandler) | ||
if !isRelayedV3 { | ||
return false | ||
} | ||
|
||
hasRelayer := len(relayedTx.GetRelayerAddr()) > 0 | ||
hasRelayerSignature := len(relayedTx.GetRelayerSignature()) > 0 | ||
return hasRelayer || hasRelayerSignature | ||
} |
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,70 @@ | ||
package common | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/data/smartContractResult" | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsValidRelayedTxV3(t *testing.T) { | ||
t.Parallel() | ||
|
||
scr := &smartContractResult.SmartContractResult{} | ||
require.False(t, IsValidRelayedTxV3(scr)) | ||
require.False(t, IsRelayedTxV3(scr)) | ||
|
||
notRelayedTxV3 := &transaction.Transaction{ | ||
Nonce: 1, | ||
Value: big.NewInt(100), | ||
RcvAddr: []byte("receiver"), | ||
SndAddr: []byte("sender0"), | ||
GasPrice: 100, | ||
GasLimit: 10, | ||
Signature: []byte("signature"), | ||
} | ||
require.False(t, IsValidRelayedTxV3(notRelayedTxV3)) | ||
require.False(t, IsRelayedTxV3(notRelayedTxV3)) | ||
|
||
invalidRelayedTxV3 := &transaction.Transaction{ | ||
Nonce: 1, | ||
Value: big.NewInt(100), | ||
RcvAddr: []byte("receiver"), | ||
SndAddr: []byte("sender0"), | ||
GasPrice: 100, | ||
GasLimit: 10, | ||
Signature: []byte("signature"), | ||
RelayerAddr: []byte("relayer"), | ||
} | ||
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3)) | ||
require.True(t, IsRelayedTxV3(invalidRelayedTxV3)) | ||
|
||
invalidRelayedTxV3 = &transaction.Transaction{ | ||
Nonce: 1, | ||
Value: big.NewInt(100), | ||
RcvAddr: []byte("receiver"), | ||
SndAddr: []byte("sender0"), | ||
GasPrice: 100, | ||
GasLimit: 10, | ||
Signature: []byte("signature"), | ||
RelayerSignature: []byte("signature"), | ||
} | ||
require.False(t, IsValidRelayedTxV3(invalidRelayedTxV3)) | ||
require.True(t, IsRelayedTxV3(invalidRelayedTxV3)) | ||
|
||
relayedTxV3 := &transaction.Transaction{ | ||
Nonce: 1, | ||
Value: big.NewInt(100), | ||
RcvAddr: []byte("receiver"), | ||
SndAddr: []byte("sender1"), | ||
GasPrice: 100, | ||
GasLimit: 10, | ||
Signature: []byte("signature"), | ||
RelayerAddr: []byte("relayer"), | ||
RelayerSignature: []byte("signature"), | ||
} | ||
require.True(t, IsValidRelayedTxV3(relayedTxV3)) | ||
require.True(t, IsRelayedTxV3(relayedTxV3)) | ||
} |
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
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
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
Oops, something went wrong.