Пример #1
0
    void testSeedParsing ()
    {
        testcase ("Parsing");

        // account IDs and node and account public and private
        // keys should not be parseable as seeds.

        auto const node1 = randomKeyPair(KeyType::secp256k1);

        BEAST_EXPECT(!parseGenericSeed (
                         toBase58 (TokenType::TOKEN_NODE_PUBLIC, node1.first)));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58 (TokenType::TOKEN_NODE_PRIVATE, node1.second)));

        auto const node2 = randomKeyPair(KeyType::ed25519);

        BEAST_EXPECT(!parseGenericSeed (
                         toBase58 (TokenType::TOKEN_NODE_PUBLIC, node2.first)));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58 (TokenType::TOKEN_NODE_PRIVATE, node2.second)));

        auto const account1 = generateKeyPair(
                                  KeyType::secp256k1, randomSeed ());

        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(calcAccountID(account1.first))));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, account1.first)));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(TokenType::TOKEN_ACCOUNT_SECRET, account1.second)));

        auto const account2 = generateKeyPair(
                                  KeyType::ed25519, randomSeed ());

        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(calcAccountID(account2.first))));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(TokenType::TOKEN_ACCOUNT_PUBLIC, account2.first)));
        BEAST_EXPECT(!parseGenericSeed (
                         toBase58(TokenType::TOKEN_ACCOUNT_SECRET, account2.second)));
    }
Пример #2
0
    // with activate
    void
    test_backoff2()
    {
        auto const seconds = 10000;
        testcase("backoff 2");
        TestStore store;
        TestChecker checker;
        TestStopwatch clock;
        Logic<TestChecker> logic (clock, store, checker, beast::Journal{});
        logic.addFixedPeer ("test",
            beast::IP::Endpoint::from_string("65.0.0.1:5"));
        {
            Config c;
            c.autoConnect = false;
            c.listeningPort = 1024;
            logic.config(c);
        }

        PublicKey const pk (randomKeyPair(KeyType::secp256k1).first);
        std::size_t n = 0;

        for (std::size_t i = 0; i < seconds; ++i)
        {
            auto const list = logic.autoconnect();
            if (! list.empty())
            {
                expect (list.size() == 1);
                auto const slot = logic.new_outbound_slot(list.front());
                if (! expect (logic.onConnected(slot,
                        beast::IP::Endpoint::from_string("65.0.0.2:5"))))
                    return;
                std::string s = ".";
                if (! expect (logic.activate(slot, pk, false) ==
                        PeerFinder::Result::success, "activate"))
                    return;
                logic.on_closed(slot);
                ++n;
            }
            clock.advance(std::chrono::seconds(1));
            logic.once_per_second();
        }
        // No more often than once per minute
        expect (n <= (seconds+59)/60, "backoff");
    }