-
Notifications
You must be signed in to change notification settings - Fork 465
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
Showing
4 changed files
with
90 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package pubsubManager_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dominant-strategies/go-quai/p2p/node/pubsubManager" | ||
) | ||
|
||
func TestTopicFromString(t *testing.T) { | ||
type testcase struct { | ||
input string | ||
shouldPass bool | ||
} | ||
cases := []testcase{ | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,0/blocks", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,0/headers", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/1,0/transactions", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/7,0/blocks", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/15,0/woHeaders", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/15,15/woHeaders", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,15/woHeaders", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,0,0/blocks", false}, // bad location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,cinnamon buns/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,a/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/16,0/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/16,16/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/15,16/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/128,0/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/-1,0/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0,-1/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/-1000000,0/blocks", false}, // bad zone location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/-1/blocks", false}, // bad region location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/0/blocks", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/1/blocks", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/15/blocks", true}, | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/16/blocks", false}, // bad region location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/PoW vs PoS? Which is right?/blocks", false}, // bad region location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011/10000000/blocks", false}, // bad region location | ||
{"0x0011223344556677889900112233445566778899001122334455667788990011//blocks", true}, | ||
{"0x001122334455667788990011223344556677889900112233445566778899001/0,0/blocks", false}, // hash too short | ||
{"0x00112233445566778899001122334455667788990011223344556677889900111/0,0/blocks", false}, // hash too long | ||
{"0xG011223344556677889900112233445566778899001122334455667788990011/0,0/blocks", false}, // invalid hex char | ||
} | ||
for _, c := range cases { | ||
topic, err := pubsubManager.TopicFromString(c.input) | ||
if err != nil { | ||
if c.shouldPass { | ||
t.Errorf("Error building topic for \"%s\": %s", c.input, err.Error()) | ||
} | ||
continue | ||
} | ||
if toString := topic.String(); toString != c.input { | ||
t.Logf("expected %s", c.input) | ||
t.Logf("actual %s", toString) | ||
t.Errorf("Encoded string does not match decoded") | ||
} | ||
} | ||
} |