-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BCF-2901 Fix potential JAID collisions in multi chain env (#11821)
* Fix potential JAID collisions in multi chain env This fixes some rest api responses getting omitted when the JAID was same across multiple chains * Add JAID constructor that formats JAID with chainID prefix * minor test fix * Flip FormatWithPrefixedChainID params to make more sense
- Loading branch information
Showing
26 changed files
with
275 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package presenters | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/manyminds/api2go/jsonapi" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/cosmostest" | ||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/solanatest" | ||
) | ||
|
||
func TestSolanaMessageResource(t *testing.T) { | ||
id := "1" | ||
chainID := solanatest.RandomChainID() | ||
r := NewSolanaMsgResource(id, chainID) | ||
assert.Equal(t, chainID, r.ChainID) | ||
|
||
b, err := jsonapi.Marshal(r) | ||
require.NoError(t, err) | ||
|
||
expected := fmt.Sprintf(` | ||
{ | ||
"data":{ | ||
"type":"solana_messages", | ||
"id":"%s/%s", | ||
"attributes":{ | ||
"ChainID":"%s", | ||
"from":"", | ||
"to":"", | ||
"amount":0 | ||
} | ||
} | ||
} | ||
`, chainID, id, chainID) | ||
|
||
assert.JSONEq(t, expected, string(b)) | ||
} | ||
|
||
func TestCosmosMessageResource(t *testing.T) { | ||
id := "1" | ||
chainID := cosmostest.RandomChainID() | ||
contractID := "cosmos1p3ucd3ptpw902fluyjzkq3fflq4btddac9sa3s" | ||
r := NewCosmosMsgResource(id, chainID, contractID) | ||
assert.Equal(t, chainID, r.ChainID) | ||
assert.Equal(t, contractID, r.ContractID) | ||
|
||
b, err := jsonapi.Marshal(r) | ||
require.NoError(t, err) | ||
|
||
expected := fmt.Sprintf(` | ||
{ | ||
"data":{ | ||
"type":"cosmos_messages", | ||
"id":"%s/%s", | ||
"attributes":{ | ||
"ChainID":"%s", | ||
"ContractID":"%s", | ||
"State":"", | ||
"TxHash":null | ||
} | ||
} | ||
} | ||
`, chainID, id, chainID, contractID) | ||
|
||
assert.JSONEq(t, expected, string(b)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package presenters | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/manyminds/api2go/jsonapi" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" | ||
) | ||
|
||
func TestEVMForwarderResource(t *testing.T) { | ||
var ( | ||
ID = int64(1) | ||
address = utils.RandomAddress() | ||
chainID = *big.NewI(4) | ||
createdAt = time.Now() | ||
updatedAt = time.Now().Add(time.Second) | ||
) | ||
fwd := forwarders.Forwarder{ | ||
ID: ID, | ||
Address: address, | ||
EVMChainID: chainID, | ||
CreatedAt: createdAt, | ||
UpdatedAt: updatedAt, | ||
} | ||
|
||
r := NewEVMForwarderResource(fwd) | ||
assert.Equal(t, fmt.Sprint(ID), r.ID) | ||
assert.Equal(t, address, r.Address) | ||
assert.Equal(t, chainID, r.EVMChainID) | ||
assert.Equal(t, createdAt, r.CreatedAt) | ||
assert.Equal(t, updatedAt, r.UpdatedAt) | ||
|
||
b, err := jsonapi.Marshal(r) | ||
require.NoError(t, err) | ||
|
||
createdAtMarshalled, err := createdAt.MarshalText() | ||
require.NoError(t, err) | ||
updatedAtMarshalled, err := updatedAt.MarshalText() | ||
require.NoError(t, err) | ||
|
||
expected := fmt.Sprintf(` | ||
{ | ||
"data":{ | ||
"type":"evm_forwarder", | ||
"id":"%d", | ||
"attributes":{ | ||
"address":"%s", | ||
"evmChainId":"%s", | ||
"createdAt":"%s", | ||
"updatedAt":"%s" | ||
} | ||
} | ||
} | ||
`, ID, strings.ToLower(address.String()), chainID.String(), string(createdAtMarshalled), string(updatedAtMarshalled)) | ||
assert.JSONEq(t, expected, string(b)) | ||
} |
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.