-
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.
- Loading branch information
1 parent
dcf8795
commit 384fea0
Showing
3 changed files
with
367 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,362 @@ | ||
package keystone | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/smartcontractkit/chainlink/integration-tests/deployment/clo/models" | ||
v1 "github.com/smartcontractkit/chainlink/integration-tests/deployment/jd/node/v1" | ||
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype" | ||
) | ||
|
||
func Test_newOcr2Node(t *testing.T) { | ||
type args struct { | ||
id string | ||
ccfgs map[chaintype.ChainType]*v1.ChainConfig | ||
csaPubKey string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantAptos bool | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "no aptos", | ||
args: args{ | ||
id: "1", | ||
ccfgs: map[chaintype.ChainType]*v1.ChainConfig{ | ||
chaintype.EVM: { | ||
|
||
Ocr2Config: &v1.OCR2Config{ | ||
P2PKeyBundle: &v1.OCR2Config_P2PKeyBundle{ | ||
PeerId: "p2p_12D3KooWMWUKdoAc2ruZf9f55p7NVFj7AFiPm67xjQ8BZBwkqyYv", | ||
PublicKey: "pubKey", | ||
}, | ||
OcrKeyBundle: &v1.OCR2Config_OCRKeyBundle{ | ||
BundleId: "bundleId", | ||
ConfigPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OffchainPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OnchainSigningAddress: "b35409a8d4f9a18da55c5b2bb08a3f5f68d44442", | ||
}, | ||
}, | ||
}, | ||
}, | ||
csaPubKey: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | ||
}, | ||
}, | ||
{ | ||
name: "with aptos", | ||
args: args{ | ||
id: "1", | ||
ccfgs: map[chaintype.ChainType]*v1.ChainConfig{ | ||
chaintype.EVM: { | ||
|
||
Ocr2Config: &v1.OCR2Config{ | ||
P2PKeyBundle: &v1.OCR2Config_P2PKeyBundle{ | ||
PeerId: "p2p_12D3KooWMWUKdoAc2ruZf9f55p7NVFj7AFiPm67xjQ8BZBwkqyYv", | ||
PublicKey: "pubKey", | ||
}, | ||
OcrKeyBundle: &v1.OCR2Config_OCRKeyBundle{ | ||
BundleId: "bundleId", | ||
ConfigPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OffchainPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OnchainSigningAddress: "b35409a8d4f9a18da55c5b2bb08a3f5f68d44442", | ||
}, | ||
}, | ||
}, | ||
chaintype.Aptos: { | ||
|
||
Ocr2Config: &v1.OCR2Config{ | ||
P2PKeyBundle: &v1.OCR2Config_P2PKeyBundle{ | ||
PeerId: "p2p_12D3KooWMWUKdoAc2ruZf9f55p7NVFj7AFiPm67xjQ8BZB11111", | ||
PublicKey: "pubKey", | ||
}, | ||
OcrKeyBundle: &v1.OCR2Config_OCRKeyBundle{ | ||
BundleId: "bundleId2", | ||
ConfigPublicKey: "0000015fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OffchainPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OnchainSigningAddress: "111409a8d4f9a18da55c5b2bb08a3f5f68d44777", | ||
}, | ||
}, | ||
}, | ||
}, | ||
csaPubKey: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | ||
}, | ||
wantAptos: true, | ||
}, | ||
{ | ||
name: "bad csa key", | ||
args: args{ | ||
id: "1", | ||
ccfgs: map[chaintype.ChainType]*v1.ChainConfig{ | ||
chaintype.EVM: { | ||
|
||
Ocr2Config: &v1.OCR2Config{ | ||
P2PKeyBundle: &v1.OCR2Config_P2PKeyBundle{ | ||
PeerId: "p2p_12D3KooWMWUKdoAc2ruZf9f55p7NVFj7AFiPm67xjQ8BZBwkqyYv", | ||
PublicKey: "pubKey", | ||
}, | ||
OcrKeyBundle: &v1.OCR2Config_OCRKeyBundle{ | ||
BundleId: "bundleId", | ||
ConfigPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OffchainPublicKey: "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1", | ||
OnchainSigningAddress: "b35409a8d4f9a18da55c5b2bb08a3f5f68d44442", | ||
}, | ||
}, | ||
}, | ||
}, | ||
csaPubKey: "not hex", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := newOcr2Node(tt.args.id, tt.args.ccfgs, tt.args.csaPubKey) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("newOcr2Node() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if tt.wantErr { | ||
return | ||
} | ||
assert.NotNil(t, got.ethOcr2KeyBundle) | ||
assert.NotNil(t, got.p2pKeyBundle) | ||
assert.NotNil(t, got.Signer) | ||
assert.NotNil(t, got.EncryptionPublicKey) | ||
assert.NotEmpty(t, got.csaKey) | ||
assert.NotEmpty(t, got.P2PKey) | ||
assert.Equal(t, tt.wantAptos, got.aptosOcr2KeyBundle != nil) | ||
}) | ||
} | ||
} | ||
|
||
func Test_mapDonsToNodes(t *testing.T) { | ||
var ( | ||
pubKey = "03dacd15fc96c965c648e3623180de002b71a97cf6eeca9affb91f461dcd6ce1" | ||
evmSig = "b35409a8d4f9a18da55c5b2bb08a3f5f68d44442" | ||
aptosSig = "b35409a8d4f9a18da55c5b2bb08a3f5f68d44442b35409a8d4f9a18da55c5b2bb08a3f5f68d44442" | ||
peerID = "p2p_12D3KooWMWUKdoAc2ruZf9f55p7NVFj7AFiPm67xjQ8BZBwkqyYv" | ||
// todo: these should be defined in common | ||
writerCap = 3 | ||
ocr3Cap = 2 | ||
) | ||
type args struct { | ||
dons []DonCapabilities | ||
excludeBootstraps bool | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "writer evm only", | ||
args: args{ | ||
dons: []DonCapabilities{ | ||
{ | ||
Name: "ok writer", | ||
Nops: []*models.NodeOperator{ | ||
{ | ||
Nodes: []*models.Node{ | ||
{ | ||
PublicKey: &pubKey, | ||
ChainConfigs: []*models.NodeChainConfig{ | ||
{ | ||
ID: "1", | ||
Network: &models.Network{ | ||
ChainType: models.ChainTypeEvm, | ||
}, | ||
Ocr2Config: &models.NodeOCR2Config{ | ||
P2pKeyBundle: &models.NodeOCR2ConfigP2PKeyBundle{ | ||
PeerID: peerID, | ||
}, | ||
OcrKeyBundle: &models.NodeOCR2ConfigOCRKeyBundle{ | ||
ConfigPublicKey: pubKey, | ||
OffchainPublicKey: pubKey, | ||
OnchainSigningAddress: evmSig, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Capabilities: []kcr.CapabilitiesRegistryCapability{ | ||
{ | ||
LabelledName: "writer", | ||
Version: "1", | ||
CapabilityType: uint8(writerCap), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "err if no evm chain", | ||
args: args{ | ||
dons: []DonCapabilities{ | ||
{ | ||
Name: "bad chain", | ||
Nops: []*models.NodeOperator{ | ||
{ | ||
Nodes: []*models.Node{ | ||
{ | ||
PublicKey: &pubKey, | ||
ChainConfigs: []*models.NodeChainConfig{ | ||
{ | ||
ID: "1", | ||
Network: &models.Network{ | ||
ChainType: models.ChainTypeSolana, | ||
}, | ||
Ocr2Config: &models.NodeOCR2Config{ | ||
P2pKeyBundle: &models.NodeOCR2ConfigP2PKeyBundle{ | ||
PeerID: peerID, | ||
}, | ||
OcrKeyBundle: &models.NodeOCR2ConfigOCRKeyBundle{ | ||
ConfigPublicKey: pubKey, | ||
OffchainPublicKey: pubKey, | ||
OnchainSigningAddress: evmSig, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Capabilities: []kcr.CapabilitiesRegistryCapability{ | ||
{ | ||
LabelledName: "writer", | ||
Version: "1", | ||
CapabilityType: uint8(writerCap), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "ocr3 cap err if no aptos chain", | ||
args: args{ | ||
dons: []DonCapabilities{ | ||
{ | ||
Name: "bad chain", | ||
Nops: []*models.NodeOperator{ | ||
{ | ||
Nodes: []*models.Node{ | ||
{ | ||
PublicKey: &pubKey, | ||
ChainConfigs: []*models.NodeChainConfig{ | ||
{ | ||
ID: "1", | ||
Network: &models.Network{ | ||
ChainType: models.ChainTypeEvm, | ||
}, | ||
Ocr2Config: &models.NodeOCR2Config{ | ||
P2pKeyBundle: &models.NodeOCR2ConfigP2PKeyBundle{ | ||
PeerID: peerID, | ||
}, | ||
OcrKeyBundle: &models.NodeOCR2ConfigOCRKeyBundle{ | ||
ConfigPublicKey: pubKey, | ||
OffchainPublicKey: pubKey, | ||
OnchainSigningAddress: evmSig, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Capabilities: []kcr.CapabilitiesRegistryCapability{ | ||
{ | ||
LabelledName: "ocr3", | ||
Version: "1", | ||
CapabilityType: uint8(ocr3Cap), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "ocr3 cap evm & aptos", | ||
args: args{ | ||
dons: []DonCapabilities{ | ||
{ | ||
Name: "bad chain", | ||
Nops: []*models.NodeOperator{ | ||
{ | ||
Nodes: []*models.Node{ | ||
{ | ||
PublicKey: &pubKey, | ||
ChainConfigs: []*models.NodeChainConfig{ | ||
{ | ||
ID: "1", | ||
Network: &models.Network{ | ||
ChainType: models.ChainTypeEvm, | ||
}, | ||
Ocr2Config: &models.NodeOCR2Config{ | ||
P2pKeyBundle: &models.NodeOCR2ConfigP2PKeyBundle{ | ||
PeerID: peerID, | ||
}, | ||
OcrKeyBundle: &models.NodeOCR2ConfigOCRKeyBundle{ | ||
ConfigPublicKey: pubKey, | ||
OffchainPublicKey: pubKey, | ||
OnchainSigningAddress: evmSig, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: "2", | ||
Network: &models.Network{ | ||
ChainType: models.ChainTypeAptos, | ||
}, | ||
Ocr2Config: &models.NodeOCR2Config{ | ||
P2pKeyBundle: &models.NodeOCR2ConfigP2PKeyBundle{ | ||
PeerID: peerID, | ||
}, | ||
OcrKeyBundle: &models.NodeOCR2ConfigOCRKeyBundle{ | ||
ConfigPublicKey: pubKey, | ||
OffchainPublicKey: pubKey, | ||
OnchainSigningAddress: aptosSig, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Capabilities: []kcr.CapabilitiesRegistryCapability{ | ||
{ | ||
LabelledName: "ocr3", | ||
Version: "1", | ||
CapabilityType: uint8(ocr3Cap), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := mapDonsToNodes(tt.args.dons, tt.args.excludeBootstraps) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("mapDonsToNodes() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
}) | ||
} | ||
} |