def run_test_with_zmq (self, ctx): self.games = {} for g in ["a", "b", "ignored"]: self.games[g] = ZmqSubscriber (ctx, self.address, g) self.games[g].subscribe ("game-block-attach") self.games[g].subscribe ("game-block-detach") self._test_currencyIgnored () self._test_register () self._test_blockData () self._test_multipleUpdates () self._test_duplicateKeys () self._test_inputs () self._test_moveWithCurrency () self._test_adminCmd () self._test_duplicateAdminCmds () self._test_reorg () self._test_sendUpdates () self._test_maxGameBlockAttaches () # After all the real tests, verify no more notifications are there. # This especially verifies that the "ignored" game we are subscribed to # has no notifications (because it is not tracked by the daemon). self.log.info ("Verifying that there are no unexpected messages...") for _, sub in self.games.items (): sub.assertNoMessage ()
def run_test_with_zmq(self, ctx): games = {} for g in ["a", "b", "ignored"]: games[g] = ZmqSubscriber(ctx, self.address, g) games[g].subscribe("game-block-attach") games[g].subscribe("game-block-detach") # Test initial set as configured by the startup options. self.log.info("Testing trackedgames...") assert_equal(set(self.node.trackedgames()), set(["a", "b", "other"])) # Remove some tracked (and non-tracked) games. self.node.trackedgames("remove", "b") self.node.trackedgames("remove", "not-there") assert_equal(set(self.node.trackedgames()), set(["a", "other"])) # Add a game that was previously not tracked. self.node.trackedgames("add", "ignored") self.node.trackedgames("add", "a") assert_equal(set(self.node.trackedgames()), set(["a", "ignored", "other"])) # Trigger an update to make sure the modified list is taken into account. self.node.generate(1) topic, _ = games["a"].receive() assert_equal(topic, "game-block-attach json a") topic, _ = games["ignored"].receive() assert_equal(topic, "game-block-attach json ignored") # Restore original setting. self.node.trackedgames("add", "b") self.node.trackedgames("remove", "ignored") assert_equal(set(self.node.trackedgames()), set(["a", "b", "other"])) # After all the real tests, verify no more notifications are there. # This especially verifies that the "ignored" game we are subscribed to # has no notifications (because it is not tracked by the daemon). self.log.info("Verifying that there are no unexpected messages...") for _, sub in games.items(): sub.assertNoMessage() # Restart the node without any active ZMQ notifications. The tracked games # should still work fine. self.log.info("Testing without game ZMQ notifications...") args = ["-trackgame=a", "-zmqpubhashblock=%s" % self.address] self.restart_node(0, extra_args=args) self.node.trackedgames("add", "b") assert_equal(set(self.node.trackedgames()), set(["a", "b"])) game = ZmqSubscriber(ctx, self.address, "a") game.subscribe("game-block-attach") self.node.generate(1) game.assertNoMessage()
def _test_blockDetach(self, ctx): self.log.info("Testing block detach...") # Enable also block notifications, so that we can test the relationship # between pending tx and the block detach (the detach should come first). # We use a new game ID here so that we do not mess up other tests. args = [] args.append("-zmqpubgameblocks=%s" % self.address) args.append("-zmqpubgamepending=%s" % self.address) args.append("-trackgame=detach") self.restart_node(0, extra_args=args) notifier = ZmqSubscriber(ctx, self.address, "detach") notifier.subscribe("game-pending-move") notifier.subscribe("game-block-detach") self.node.generate(1) txid = self.node.name_update("p/x", json.dumps({"g": { "detach": "detached" }})) topic, data = notifier.receive() assert_equal(topic, "game-pending-move json detach") assertMove(data, txid, "x", "detached") blk = self.node.generate(1)[0] self.node.invalidateblock(blk) topic, data = notifier.receive() assert_equal(topic, "game-block-detach json detach") assert_equal(data["block"]["hash"], blk) assert_equal(len(data["moves"]), 1) assertMove(data["moves"][0], txid, "x", "detached") topic, data = notifier.receive() assert_equal(topic, "game-pending-move json detach") assertMove(data, txid, "x", "detached") notifier.assertNoMessage()
def run_test_with_zmq(self, ctx): self.games = {} for g in ["a", "b", "ignored"]: self.games[g] = ZmqSubscriber(ctx, self.address, g) self.games[g].subscribe("game-pending-move") self._test_currencyIgnored() self._test_register() self._test_notWhenMined() self._test_update() self._test_multipleGames() self._test_blockDetach(ctx) # After all the real tests, verify no more notifications are there. # This especially verifies that the "ignored" game we are subscribed to # has no notifications (because it is not tracked by the daemon). self.log.info("Verifying that there are no unexpected messages...") for _, sub in self.games.items(): sub.assertNoMessage()