-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure protocol naming matches latest Starknet p2p spec
The change ensures that DHT protocol follow latest Starknet specification.
- Loading branch information
1 parent
4ff174d
commit f5bdcb6
Showing
5 changed files
with
133 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
package starknet | ||
|
||
import ( | ||
"github.com/NethermindEth/juno/utils" | ||
"github.com/libp2p/go-libp2p/core/protocol" | ||
) | ||
|
||
const Prefix = "/starknet" | ||
|
||
func HeadersPID() protocol.ID { | ||
return Prefix + "/headers/0.1.0-rc.0" | ||
func HeadersPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync/headers/0.1.0-rc.0") | ||
} | ||
|
||
func EventsPID() protocol.ID { | ||
return Prefix + "/events/0.1.0-rc.0" | ||
func EventsPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync/events/0.1.0-rc.0") | ||
} | ||
|
||
func TransactionsPID() protocol.ID { | ||
return Prefix + "/transactions/0.1.0-rc.0" | ||
func TransactionsPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync/transactions/0.1.0-rc.0") | ||
} | ||
|
||
func ClassesPID() protocol.ID { | ||
return Prefix + "/classes/0.1.0-rc.0" | ||
func ClassesPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync/classes/0.1.0-rc.0") | ||
} | ||
|
||
func StateDiffPID() protocol.ID { | ||
return Prefix + "/state_diffs/0.1.0-rc.0" | ||
func StateDiffPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync/state_diffs/0.1.0-rc.0") | ||
} | ||
|
||
func DHTPrefixPID(network *utils.Network) protocol.ID { | ||
return protocol.ID(Prefix + "/" + network.L2ChainID + "/sync") | ||
} |
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,67 @@ | ||
package starknet | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/NethermindEth/juno/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProtocolIDs(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
network *utils.Network | ||
pidFunc func(*utils.Network) string | ||
expected string | ||
}{ | ||
{ | ||
name: "HeadersPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(HeadersPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync/headers/0.1.0-rc.0", | ||
}, | ||
{ | ||
name: "EventsPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(EventsPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync/events/0.1.0-rc.0", | ||
}, | ||
{ | ||
name: "TransactionsPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(TransactionsPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync/transactions/0.1.0-rc.0", | ||
}, | ||
{ | ||
name: "ClassesPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(ClassesPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync/classes/0.1.0-rc.0", | ||
}, | ||
{ | ||
name: "StateDiffPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(StateDiffPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync/state_diffs/0.1.0-rc.0", | ||
}, | ||
{ | ||
name: "DHTPrefixPID with SN_MAIN", | ||
network: &utils.Mainnet, | ||
pidFunc: func(n *utils.Network) string { return string(DHTPrefixPID(n)) }, | ||
expected: "/starknet/SN_MAIN/sync", | ||
}, | ||
{ | ||
name: "HeadersPID with SN_SEPOLIA", | ||
network: &utils.Sepolia, | ||
pidFunc: func(n *utils.Network) string { return string(HeadersPID(n)) }, | ||
expected: "/starknet/SN_SEPOLIA/sync/headers/0.1.0-rc.0", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := tc.pidFunc(tc.network) | ||
assert.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |