-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09a2751
commit 68dbf89
Showing
11 changed files
with
103 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package common | ||
|
||
import "github.com/multiversx/mx-chain-core-go/data" | ||
|
||
// IsRelayedTxV3 returns true if the provided transaction is of type relayed v3 | ||
func IsRelayedTxV3(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 | ||
} |
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,41 @@ | ||
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 TestIsRelayedTxV3(t *testing.T) { | ||
t.Parallel() | ||
|
||
scr := &smartContractResult.SmartContractResult{} | ||
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, IsRelayedTxV3(notRelayedTxV3)) | ||
|
||
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, 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