コード例 #1
0
  def run_test (self):
    NameTestFramework.run_test (self)

    # Decode name_new.
    new = self.nodes[0].name_new ("my-name")
    self.generate (0, 10)
    data = self.decodeNameTx (0, new[0])
    assert_equal (data['op'], "name_new")
    assert 'hash' in data

    # Decode name_firstupdate.
    first = self.firstupdateName (0, "my-name", new, "initial value")
    self.generate (0, 5)
    data = self.decodeNameTx (0, first)
    assert_equal (data['op'], "name_firstupdate")
    assert_equal (data['name'], "my-name")
    assert_equal (data['value'], "initial value")
    assert_equal (data['rand'], new[1])

    # Decode name_update.
    upd = self.nodes[0].name_update ("my-name", "new value")
    self.generate (0, 1)
    data = self.decodeNameTx (0, upd)
    assert_equal (data['op'], "name_update")
    assert_equal (data['name'], "my-name")
    assert_equal (data['value'], "new value")

    # Perform a rawtx name update together with an atomic currency transaction.
    # We send the test name from 0 to 1 and some coins from 1 to 0.  In other
    # words, perform an atomic name trade.

    balanceA = self.nodes[0].getbalance ()
    balanceB = self.nodes[1].getbalance ()
    price = Decimal ("1.0")
    fee = Decimal ("0.01")

    self.atomicTrade ("my-name", "enjoy", price, fee, 0, 1)
    self.generate (3, 1)

    data = self.checkName (3, "my-name", "enjoy", None, False)
    validate = self.nodes[1].validateaddress (data['address'])
    assert validate['ismine']
    data = self.nodes[0].name_list ("my-name")
    assert_equal (len (data), 1)
    assert_equal (data[0]['name'], "my-name")
    assert_equal (data[0]['transferred'], True)
    data = self.nodes[1].name_list ("my-name")
    assert_equal (len (data), 1)
    assert_equal (data[0]['name'], "my-name")
    assert_equal (data[0]['transferred'], False)

    # Node 0 also got a block matured.  Take this into account.
    assert_equal (balanceA + price + Decimal ("50.0"),
                  self.nodes[0].getbalance ())
    assert_equal (balanceB - price - fee, self.nodes[1].getbalance ())
コード例 #2
0
ファイル: game_feepolicy.py プロジェクト: fsb4000/huntercore
  def run_test (self):
    NameTestFramework.run_test (self)

    # Send ordinary tx and verify that it has low fee.
    addr = self.nodes[1].getnewaddress ()
    txid = self.nodes[0].sendtoaddress (addr, Decimal('1'))
    self.mineAndVerify ("currency tx", txid, Decimal('0'), Decimal('0.005'))

    # Register a hunter.
    txid = self.nodes[0].name_register ("hunter", '{"color":0}')
    self.mineAndVerify ("name_register", txid, Decimal('1'), Decimal('1.005'))

    # Send messages of various lengths.
    self.verifyUpdateWithLength (99, Decimal ('0.01'))
    self.verifyUpdateWithLength (100, Decimal ('0.012'))
    self.verifyUpdateWithLength (199, Decimal ('0.012'))
    self.verifyUpdateWithLength (200, Decimal ('0.014'))
コード例 #3
0
ファイル: name_list.py プロジェクト: deLeewit/namecoin-core
  def run_test (self):
    NameTestFramework.run_test (self)

    assert_equal (self.nodes[0].name_list (), [])
    assert_equal (self.nodes[1].name_list (), [])

    newA = self.nodes[0].name_new ("name-a")
    newB = self.nodes[1].name_new ("name-b");
    self.generate (0, 10)
    self.firstupdateName (0, "name-a", newA, "value-a")
    self.firstupdateName (1, "name-b", newB, "value-b")
    self.generate (1, 5)

    arr = self.nodes[0].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "value-a", False, False)
    arr = self.nodes[1].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-b", "value-b", False, False)

    assert_equal (self.nodes[0].name_list ("name-b"), [])
    assert_equal (self.nodes[1].name_list ("name-a"), [])

    # Transfer a name away and check that name_list updates accordingly.

    addrB = self.nodes[1].getnewaddress ()
    self.nodes[0].name_update ("name-a", "enjoy", addrB)
    arr = self.nodes[0].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "value-a", False, False)

    self.generate (0, 1)
    arr = self.nodes[0].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "enjoy", False, True)
    arr = self.nodes[1].name_list ()
    assert_equal (len (arr), 2)
    self.checkNameStatus (arr[0], "name-a", "enjoy", False, False)
    self.checkNameStatus (arr[1], "name-b", "value-b", False, False)

    # Updating the name in the new wallet shouldn't change the
    # old wallet's name_list entry.
    self.nodes[1].name_update ("name-a", "new value")
    self.generate (0, 1)
    arr = self.nodes[0].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "enjoy", False, True)
    arr = self.nodes[1].name_list ("name-a")
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "new value", False, False)

    # Transfer it back and see that it updates in wallet A.
    addrA = self.nodes[0].getnewaddress ()
    self.nodes[1].name_update ("name-a", "sent", addrA)
    self.generate (0, 1)
    arr = self.nodes[0].name_list ()
    assert_equal (len (arr), 1)
    self.checkNameStatus (arr[0], "name-a", "sent", False, False)

    # Let name-b expire.
    self.generate (0, 25)
    arr = self.nodes[1].name_list ()
    assert_equal (len (arr), 2)
    self.checkNameStatus (arr[0], "name-a", "sent", False, True)
    self.checkNameStatus (arr[1], "name-b", "value-b", True, False)
コード例 #4
0
ファイル: name_wallet.py プロジェクト: IXCoin-Dev/ixcore
  def run_test (self):
    NameTestFramework.run_test (self)
    
    # Note that the next 50 maturing blocks will be for nodes 0 and 1.
    # Thus we use 2 and 3 for the tests, because their balance
    # will stay constant over time except for our explicit transactions.

    self.checkBalances ()

    # Register and update a name.  Check changes to the balance.
    newA = self.nodes[2].name_new ("name-a")
    self.generate (0, 5)
    self.checkBalances (newFee)
    firstA = self.firstupdateName (2, "name-a", newA, "value")
    self.generate (0, 10)
    self.checkBalances (firstFee)
    updA = self.nodes[2].name_update ("name-a", "new value")
    self.generate (0, 1)
    self.checkBalances (updFee)

    # Check the transactions.
    self.checkTx (2, newA[0], zero, -newFee,
                  [['send', 'new', zero, -newFee]])
    self.checkTx (2, firstA, zero, -firstFee,
                  [['send', 'update: name-a', zero, -firstFee]])
    self.checkTx (2, updA, zero, -updFee,
                  [['send', 'update: name-a', zero, -updFee]])

    # Send a name from 1 to 2 by firstupdate and update.
    addrB = self.nodes[3].getnewaddress ()
    newB = self.nodes[2].name_new ("name-b")
    newC = self.nodes[2].name_new ("name-c")
    self.generate (0, 5)
    self.checkBalances (2 * newFee)
    firstB = self.firstupdateName (2, "name-b", newB, "value", addrB)
    firstC = self.firstupdateName (2, "name-c", newC, "value")
    self.generate (0, 10)
    self.checkBalances (2 * firstFee)
    updC = self.nodes[2].name_update ("name-c", "new value", addrB)
    self.generate (0, 1)
    self.checkBalances (updFee)

    # Check the receiving transactions on B.
    self.checkTx (3, firstB, zero, None,
                  [['receive', 'update: name-b', zero, None]])
    self.checkTx (3, updC, zero, None,
                  [['receive', 'update: name-c', zero, None]])

    # Use the rawtx API to build a simultaneous name update and currency send.
    # This is done as an atomic name trade.  Note, though, that the
    # logic is a bit confused by "coin join" transactions and thus
    # possibly not exactly what one would expect.

    price = Decimal ("1.0")
    txid = self.atomicTrade ("name-a", "enjoy", price, 2, 3)
    self.generate (0, 1)

    self.checkBalances (-price, price)
    self.checkTx (2, txid, price, None,
                  [['receive', None, price, None]])
    self.checkTx (3, txid, -price, zero,
                  [['send', None, -price, zero],
                   ['send', 'update: name-a', zero, zero]])
コード例 #5
0
  def run_test (self):
    NameTestFramework.run_test (self)

    # Perform name_new's.  Check for too long names exception.
    newA = self.nodes[0].name_new ("node-0")
    newAconfl = self.nodes[1].name_new ("node-0")
    newB = self.nodes[1].name_new ("node-1")
    self.nodes[0].name_new ("x" * 255)
    try:
      self.nodes[0].name_new ("x" * 256)
      raise AssertionError ("too long name not recognised by name_new")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)
    self.generate (0, 5)

    # Check for exception with name_history and without -namehistory.
    try:
      self.nodes[0].name_history ("node-0")
      raise AssertionError ("name_history without -namehistory works")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -1)

    # first_update the names.  Check for too long values.
    addrA = self.nodes[0].getnewaddress ()
    txidA = self.firstupdateName (0, "node-0", newA, "value-0", addrA)
    try:
      self.firstupdateName (1, "node-1", newB, "x" * 521)
      raise AssertionError ("too long value not recognised by name_firstupdate")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)
    self.firstupdateName (1, "node-1", newB, "x" * 520)

    # Check for mempool conflict detection with registration of "node-0".
    self.sync_all ()
    try:
      self.firstupdateName (1, "node-0", newAconfl, "foo")
      raise AssertionError ("name_firstupdate didn't catch conflict")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)
    
    # Check that the name appears when the name_new is ripe.

    self.generate (0, 7)
    try:
      self.nodes[1].name_show ("node-0")
      raise AssertionError ("name available when it should not yet be")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    try:
      self.nodes[1].name_history ("node-0")
      raise AssertionError ("name available when it should not yet be")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    self.generate (0, 1)

    data = self.checkName (1, "node-0", "value-0", 30, False)
    assert_equal (data['address'], addrA)
    assert_equal (data['txid'], txidA)
    assert_equal (data['height'], 213)

    self.checkNameHistory (1, "node-0", ["value-0"])
    self.checkNameHistory (1, "node-1", ["x" * 520])

    # Check for error with rand mismatch (wrong name)
    newA = self.nodes[0].name_new ("test-name")
    self.generate (0, 10)
    try:
      self.firstupdateName (0, "test-name-wrong", newA, "value")
      raise AssertionError ("wrong rand value not caught by name_firstupdate")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)

    # Check for mismatch with prev tx from another node for name_firstupdate
    # and name_update.
    try:
      self.firstupdateName (1, "test-name", newA, "value")
      raise AssertionError ("wrong node can firstupdate a name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    self.firstupdateName (0, "test-name", newA, "test-value")

    # Check for disallowed firstupdate when the name is active.
    newSteal = self.nodes[1].name_new ("node-0")
    newSteal2 = self.nodes[1].name_new ("node-0")
    self.generate (0, 19)
    self.checkName (1, "node-0", "value-0", 1, False)
    try:
      self.firstupdateName (1, "node-0", newSteal, "stolen")
      raise AssertionError ("name stolen before expiry")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)

    # Check for "stealing" of the name after expiry.
    self.generate (0, 1)
    self.firstupdateName (1, "node-0", newSteal, "stolen")
    self.checkName (1, "node-0", "value-0", 0, True)
    self.generate (0, 1)
    self.checkName (1, "node-0", "stolen", 30, False)
    self.checkNameHistory (1, "node-0", ["value-0", "stolen"])

    # Check for error when firstupdating an active name, but this time
    # without the check present in the RPC call itself.  This should still not
    # be allowed and should be prevented by the mempool logic.  There was a bug
    # that allowed these transactiosn to get into the mempool, so make
    # sure it is no longer there.
    try:
      self.firstupdateName (1, "node-0", newSteal2, "unstolen",
                            allowActive = True)
      raise AssertionError ("name stolen before expiry with allowActive")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    assert_equal (self.nodes[1].getrawmempool (), [])
    self.checkName (1, "node-0", "stolen", None, False)

    # Check basic updating.
    try:
      self.nodes[0].name_update ("test-name", "x" * 521)
      raise AssertionError ("update to too long value allowed")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)
    self.nodes[0].name_update ("test-name", "x" * 520)
    self.checkName (0, "test-name", "test-value", None, False)
    self.generate (0, 1)
    self.checkName (1, "test-name", "x" * 520, 30, False)
    self.checkNameHistory (1, "test-name", ["test-value", "x" * 520])

    addrB = self.nodes[1].getnewaddress ()
    self.nodes[0].name_update ("test-name", "sent", addrB)
    self.generate (0, 1)
    data = self.checkName (0, "test-name", "sent", 30, False)
    assert_equal (data['address'], addrB)
    self.nodes[1].name_update ("test-name", "updated")
    self.generate (0, 1)
    data = self.checkName (0, "test-name", "updated", 30, False)
    self.checkNameHistory (1, "test-name",
                           ["test-value", "x" * 520, "sent", "updated"])

    # Invalid updates.
    try:
      self.nodes[1].name_update ("wrong-name", "foo")
      raise AssertionError ("invalid name updated")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)
    try:
      self.nodes[0].name_update ("test-name", "stolen?")
      raise AssertionError ("wrong node could update sent name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)

    # Reject update when another update is pending.
    self.nodes[1].name_update ("test-name", "value")
    try:
      self.nodes[1].name_update ("test-name", "new value")
      raise AssertionError ("name_update didn't catch pending other update")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)
    self.generate (0, 1)
    data = self.checkName (0, "test-name", "value", 30, False)
    self.checkNameHistory (1, "test-name", ["test-value", "x" * 520, "sent",
                                            "updated", "value"])
    
    # Update failing after expiry.  Re-registration possible.
    self.checkName (1, "node-1", "x" * 520, None, True)
    try:
      self.nodes[1].name_update ("node-1", "updated?")
      raise AssertionError ("expired name updated")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)

    newSteal = self.nodes[0].name_new ("node-1")
    self.generate (0, 10)
    self.firstupdateName (0, "node-1", newSteal, "reregistered")
    self.generate (0, 10)
    self.checkName (1, "node-1", "reregistered", 23, False)
    self.checkNameHistory (1, "node-1", ["x" * 520, "reregistered"])
コード例 #6
0
  def run_test (self):
    NameTestFramework.run_test (self)

    # It would also nice to test the "initial download" error,
    # but it will only pop up if the blockchain directory (in the cache)
    # is old enough.  This can not be guaranteed (if the cache is freshly
    # generated), so that we cannot use it as a "strict" test here.
    # Instead, only warn if the test "fails".

    initialDownloadOk = True

    try:
      self.nodes[0].name_show ("a")
      initialDownloadOk = False
    except JSONRPCException as exc:
      if exc.error['code'] != -10:
        initialDownloadOk = False
    try:
      self.nodes[1].name_history ("a")
      initialDownloadOk = False
    except JSONRPCException as exc:
      if exc.error['code'] != -10:
        initialDownloadOk = False
    try:
      self.nodes[0].name_scan ()
      initialDownloadOk = False
    except JSONRPCException as exc:
      if exc.error['code'] != -10:
        initialDownloadOk = False
    try:
      self.nodes[0].name_filter ()
      initialDownloadOk = False
    except JSONRPCException as exc:
      if exc.error['code'] != -10:
        initialDownloadOk = False

    if not initialDownloadOk:
      print "WARNING: 'initial blockchain download' check failed!"
      print ("This probably means that the blockchain was regenerated"
              + " and is fine.")

    # Mine a block so that we're no longer in initial download.
    self.generate (3, 1)

    # Initially, all should be empty.
    assert_equal (self.nodes[0].name_scan (), [])
    assert_equal (self.nodes[0].name_scan ("foo", 10), [])
    assert_equal (self.nodes[0].name_filter (), [])
    assert_equal (self.nodes[0].name_filter ("", 0, 0, 0, "stat"),
                  {"blocks": 201,"count": 0})

    # Register some names with various data, heights and expiration status.
    # Using both "aa" and "b" ensures that we can also check for the expected
    # comparison order between string length and lexicographic ordering.

    newA = self.nodes[0].name_new ("a")
    newAA = self.nodes[0].name_new ("aa")
    newB = self.nodes[1].name_new ("b")
    newC = self.nodes[2].name_new ("c")
    self.generate (3, 15)

    self.firstupdateName (0, "a", newA, "wrong value")
    self.firstupdateName (0, "aa", newAA, "value aa")
    self.firstupdateName (1, "b", newB, "value b")
    self.generate (3, 15)
    self.firstupdateName (2, "c", newC, "value c")
    self.nodes[0].name_update ("a", "value a")
    self.generate (3, 20)

    # Check the expected name_scan data values.
    scan = self.nodes[3].name_scan ()
    assert_equal (len (scan), 4)
    self.checkNameData (scan[0], "a", "value a", 11, False)
    self.checkNameData (scan[1], "b", "value b", -4, True)
    self.checkNameData (scan[2], "c", "value c", 11, False)
    self.checkNameData (scan[3], "aa", "value aa", -4, True)

    # Check for expected names in various name_scan calls.
    self.checkList (self.nodes[3].name_scan (), ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_scan ("", 0), [])
    self.checkList (self.nodes[3].name_scan ("", -1), [])
    self.checkList (self.nodes[3].name_scan ("b"), ["b", "c", "aa"])
    self.checkList (self.nodes[3].name_scan ("zz"), [])
    self.checkList (self.nodes[3].name_scan ("", 2), ["a", "b"])
    self.checkList (self.nodes[3].name_scan ("b", 1), ["b"])

    # Check the expected name_filter data values.
    scan = self.nodes[3].name_scan ()
    assert_equal (len (scan), 4)
    self.checkNameData (scan[0], "a", "value a", 11, False)
    self.checkNameData (scan[1], "b", "value b", -4, True)
    self.checkNameData (scan[2], "c", "value c", 11, False)
    self.checkNameData (scan[3], "aa", "value aa", -4, True)

    # Check for expected names in various name_filter calls.
    height = self.nodes[3].getblockcount ()
    self.checkList (self.nodes[3].name_filter (), ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("[ac]"), ["a", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 10), [])
    self.checkList (self.nodes[3].name_filter ("", 30), ["a", "c"])
    self.checkList (self.nodes[3].name_filter ("", 0, 0, 0),
                    ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 0, 0, 1), ["a"])
    self.checkList (self.nodes[3].name_filter ("", 0, 1, 4), ["b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 0, 4, 4), [])
    assert_equal (self.nodes[3].name_filter ("", 30, 0, 0, "stat"),
                  {"blocks": height, "count": 2})

    # Check test for "stat" argument.
    try:
      self.nodes[3].name_filter ("", 0, 0, 0, "string")
      raise AssertionError ("wrong check for 'stat' argument")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)
コード例 #7
0
ファイル: name_reorg.py プロジェクト: zebbra2014/namecore
    def run_test(self):
        NameTestFramework.run_test(self)

        # Register a name prior to forking the chain.  This is used
        # to test unrolling of updates (as opposed to registrations).
        newA = self.nodes[3].name_new("a")
        newBshort = self.nodes[3].name_new("b")
        newBlong = self.nodes[0].name_new("b")
        newC = self.nodes[3].name_new("c")
        self.generate(0, 10)
        self.firstupdateName(3, "a", newA, "initial value")
        self.generate(0, 5)

        # Split the network.
        self.split_network()

        # Build a long chain that registers "b" (to clash with
        # the same registration on the short chain).
        self.generate(0, 2)
        self.firstupdateName(0, "b", newBlong, "b long")
        self.generate(0, 2)
        self.checkName(0, "a", "initial value", None, False)
        self.checkName(0, "b", "b long", None, False)
        self.checkNameHistory(1, "a", ["initial value"])
        self.checkNameHistory(1, "b", ["b long"])

        # Build a short chain with an update to "a" and registrations.
        self.generate(3, 1)
        txidB = self.firstupdateName(3, "b", newBshort, "b short")
        self.firstupdateName(3, "c", newC, "c registered")
        self.nodes[3].name_update("a", "changed value")
        self.generate(3, 1)
        self.checkName(3, "a", "changed value", None, False)
        self.checkName(3, "b", "b short", None, False)
        self.checkName(3, "c", "c registered", None, False)
        self.checkNameHistory(2, "a", ["initial value", "changed value"])
        self.checkNameHistory(2, "b", ["b short"])
        self.checkNameHistory(2, "c", ["c registered"])

        # Join the network and let the long chain prevail.
        self.join_network()
        self.checkName(3, "a", "initial value", None, False)
        self.checkName(3, "b", "b long", None, False)
        self.checkNameHistory(2, "a", ["initial value"])
        self.checkNameHistory(2, "b", ["b long"])
        try:
            self.nodes[3].name_show("c")
            raise AssertionError("'c' still registered after reorg")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        try:
            self.nodes[2].name_history("c")
            raise AssertionError("'c' still registered after reorg")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)

        # Mine another block.  This should at least perform the
        # non-conflicting transactions.  It is done on node 3 so
        # that these tx are actually in the mempool.
        self.generate(3, 1, False)
        self.checkName(3, "a", "changed value", None, False)
        self.checkName(3, "b", "b long", None, False)
        self.checkName(3, "c", "c registered", None, False)
        self.checkNameHistory(2, "a", ["initial value", "changed value"])
        self.checkNameHistory(2, "b", ["b long"])
        self.checkNameHistory(2, "c", ["c registered"])

        # Check that the conflicting tx got pruned from the mempool properly
        # and is marked as conflicted in the wallet.
        assert_equal(self.nodes[0].getrawmempool(), [])
        assert_equal(self.nodes[3].getrawmempool(), [])
        data = self.nodes[3].gettransaction(txidB)
        assert data['confirmations'] < 0
コード例 #8
0
ファイル: name_multisig.py プロジェクト: IXCoin-Dev/ixcore
  def run_test (self):
    NameTestFramework.run_test (self)

    # Construct a 2-of-2 multisig address shared between two nodes.
    pubkeyA = self.getNewPubkey (0)
    pubkeyB = self.getNewPubkey (1)
    p2sh = self.nodes[0].addmultisigaddress (2, [pubkeyA, pubkeyB])
    p2sh_ = self.nodes[1].addmultisigaddress (2, [pubkeyA, pubkeyB])
    assert_equal (p2sh, p2sh_)

    # Register a new name to that address.
    new = self.nodes[0].name_new ("name")
    self.generate (0, 10)
    self.firstupdateName (0, "name", new, "value", p2sh)
    self.generate (1, 5)
    data = self.checkName (2, "name", "value", None, False)
    assert_equal (data['address'], p2sh)

    # Straight-forward name updating should fail (for both nodes).
    try:
      self.nodes[0].name_update ("name", "new value")
      raise AssertionError ("name_update allowed from single node")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    try:
      self.nodes[1].name_update ("name", "new value")
      raise AssertionError ("name_update allowed from single node")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)

    # Find some other input to add as fee.
    unspents = self.nodes[0].listunspent ()
    assert len (unspents) > 0
    feeInput = unspents[0]
    changeAddr = self.nodes[0].getnewaddress ()
    changeAmount = feeInput['amount'] - Decimal ("0.01")

    # Construct the name update as raw transaction.
    addr = self.nodes[2].getnewaddress ()
    inputs = [{"txid": data['txid'], "vout": data['vout']}, feeInput]
    outputs = {changeAddr: changeAmount}
    op = {"op": "name_update", "name": "name",
          "value": "it worked", "address": addr}
    txRaw = self.nodes[3].createrawtransaction (inputs, outputs, op)

    # Sign it partially.
    partial = self.nodes[0].signrawtransaction (txRaw)
    assert not partial['complete']
    try:
      self.nodes[2].sendrawtransaction (partial['hex'])
      raise AssertionError ("incomplete transaction accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -26)

    # Sign it fully and transmit it.
    signed = self.nodes[1].signrawtransaction (partial['hex'])
    assert signed['complete']
    tx = signed['hex']

    # Manipulate the signature to invalidate it.  This checks whether or
    # not the OP_MULTISIG is actually verified (vs just the script hash
    # compared to the redeem script).
    txData = bytearray (binascii.unhexlify (tx))
    txData[44] = (txData[44] + 10) % 256
    txManipulated = binascii.hexlify (txData)

    # Send the tx.  The manipulation should be caught (independently of
    # when strict P2SH checks are enabled, since they are enforced
    # mandatorily in the mempool).
    try:
      self.nodes[2].sendrawtransaction (txManipulated)
      raise AssertionError ("manipulated signature tx accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -26)
    self.nodes[2].sendrawtransaction (tx)
    self.generate (3, 1)

    # Check that it was transferred correctly.
    self.checkName (3, "name", "it worked", None, False)
    self.nodes[2].name_update ("name", "changed")
    self.generate (3, 1)
    self.checkName (3, "name", "changed", None, False)
コード例 #9
0
    def run_test(self):
        NameTestFramework.run_test(self)

        # Perform name_new's.  Check for too long names exception.
        newA = self.nodes[0].name_new("node-0")
        newAconfl = self.nodes[1].name_new("node-0")
        newB = self.nodes[1].name_new("node-1")
        self.nodes[0].name_new("x" * 255)
        try:
            self.nodes[0].name_new("x" * 256)
            raise AssertionError("too long name not recognised by name_new")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -8)
        self.generate(0, 5)

        # Check for exception with name_history and without -namehistory.
        try:
            self.nodes[0].name_history("node-0")
            raise AssertionError("name_history without -namehistory works")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -1)

        # first_update the names.  Check for too long values.
        addrA = self.nodes[0].getnewaddress()
        txidA = self.firstupdateName(0, "node-0", newA, "value-0", addrA)
        try:
            self.firstupdateName(1, "node-1", newB, "x" * 521)
            raise AssertionError(
                "too long value not recognised by name_firstupdate")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -8)
        self.firstupdateName(1, "node-1", newB, "x" * 520)

        # Check for mempool conflict detection with registration of "node-0".
        self.sync_all()
        try:
            self.firstupdateName(1, "node-0", newAconfl, "foo")
            raise AssertionError("name_firstupdate didn't catch conflict")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)

        # Check that the name appears when the name_new is ripe.

        self.generate(0, 7)
        try:
            self.nodes[1].name_show("node-0")
            raise AssertionError("name available when it should not yet be")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        try:
            self.nodes[1].name_history("node-0")
            raise AssertionError("name available when it should not yet be")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        self.generate(0, 1)

        data = self.checkName(1, "node-0", "value-0", 30, False)
        assert_equal(data['address'], addrA)
        assert_equal(data['txid'], txidA)
        assert_equal(data['height'], 213)

        self.checkNameHistory(1, "node-0", ["value-0"])
        self.checkNameHistory(1, "node-1", ["x" * 520])

        # Check for error with rand mismatch (wrong name)
        newA = self.nodes[0].name_new("test-name")
        self.generate(0, 10)
        try:
            self.firstupdateName(0, "test-name-wrong", newA, "value")
            raise AssertionError(
                "wrong rand value not caught by name_firstupdate")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)

        # Check for mismatch with prev tx from another node for name_firstupdate
        # and name_update.
        try:
            self.firstupdateName(1, "test-name", newA, "value")
            raise AssertionError("wrong node can firstupdate a name")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        self.firstupdateName(0, "test-name", newA, "test-value")

        # Check for disallowed firstupdate when the name is active.
        newSteal = self.nodes[1].name_new("node-0")
        newSteal2 = self.nodes[1].name_new("node-0")
        self.generate(0, 19)
        self.checkName(1, "node-0", "value-0", 1, False)
        try:
            self.firstupdateName(1, "node-0", newSteal, "stolen")
            raise AssertionError("name stolen before expiry")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)

        # Check for "stealing" of the name after expiry.
        self.generate(0, 1)
        self.firstupdateName(1, "node-0", newSteal, "stolen")
        self.checkName(1, "node-0", "value-0", 0, True)
        self.generate(0, 1)
        self.checkName(1, "node-0", "stolen", 30, False)
        self.checkNameHistory(1, "node-0", ["value-0", "stolen"])

        # Check for error when firstupdating an active name, but this time
        # without the check present in the RPC call itself.  This should still not
        # be allowed and should be prevented by the mempool logic.  There was a bug
        # that allowed these transactiosn to get into the mempool, so make
        # sure it is no longer there.
        try:
            self.firstupdateName(1,
                                 "node-0",
                                 newSteal2,
                                 "unstolen",
                                 allowActive=True)
            raise AssertionError("name stolen before expiry with allowActive")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        assert_equal(self.nodes[1].getrawmempool(), [])
        self.checkName(1, "node-0", "stolen", None, False)

        # Check basic updating.
        try:
            self.nodes[0].name_update("test-name", "x" * 521)
            raise AssertionError("update to too long value allowed")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -8)
        self.nodes[0].name_update("test-name", "x" * 520)
        self.checkName(0, "test-name", "test-value", None, False)
        self.generate(0, 1)
        self.checkName(1, "test-name", "x" * 520, 30, False)
        self.checkNameHistory(1, "test-name", ["test-value", "x" * 520])

        addrB = self.nodes[1].getnewaddress()
        self.nodes[0].name_update("test-name", "sent", addrB)
        self.generate(0, 1)
        data = self.checkName(0, "test-name", "sent", 30, False)
        assert_equal(data['address'], addrB)
        self.nodes[1].name_update("test-name", "updated")
        self.generate(0, 1)
        data = self.checkName(0, "test-name", "updated", 30, False)
        self.checkNameHistory(1, "test-name",
                              ["test-value", "x" * 520, "sent", "updated"])

        # Invalid updates.
        try:
            self.nodes[1].name_update("wrong-name", "foo")
            raise AssertionError("invalid name updated")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)
        try:
            self.nodes[0].name_update("test-name", "stolen?")
            raise AssertionError("wrong node could update sent name")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)

        # Reject update when another update is pending.
        self.nodes[1].name_update("test-name", "value")
        try:
            self.nodes[1].name_update("test-name", "new value")
            raise AssertionError(
                "name_update didn't catch pending other update")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)
        self.generate(0, 1)
        data = self.checkName(0, "test-name", "value", 30, False)
        self.checkNameHistory(
            1, "test-name",
            ["test-value", "x" * 520, "sent", "updated", "value"])

        # Update failing after expiry.  Re-registration possible.
        self.checkName(1, "node-1", "x" * 520, None, True)
        try:
            self.nodes[1].name_update("node-1", "updated?")
            raise AssertionError("expired name updated")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -25)

        newSteal = self.nodes[0].name_new("node-1")
        self.generate(0, 10)
        self.firstupdateName(0, "node-1", newSteal, "reregistered")
        self.generate(0, 10)
        self.checkName(1, "node-1", "reregistered", 23, False)
        self.checkNameHistory(1, "node-1", ["x" * 520, "reregistered"])
コード例 #10
0
ファイル: name_wallet.py プロジェクト: 36z/namecoin-core
  def run_test (self):
    NameTestFramework.run_test (self)
    
    # Note that the next 50 maturing blocks will be for nodes 0 and 1.
    # Thus we use 2 and 3 for the tests, because their balance
    # will stay constant over time except for our explicit transactions.

    self.checkBalances ()

    # Register and update a name.  Check changes to the balance.
    newA = self.nodes[2].name_new ("name-a")
    self.generate (0, 5)
    self.checkBalances (newFee)
    firstA = self.firstupdateName (2, "name-a", newA, "value")
    self.generate (0, 10)
    self.checkBalances (firstFee)
    updA = self.nodes[2].name_update ("name-a", "new value")
    self.generate (0, 1)
    self.checkBalances (updFee)

    # Check the transactions.
    self.checkTx (2, newA[0], zero, -newFee,
                  [['send', 'new', zero, -newFee]])
    self.checkTx (2, firstA, zero, -firstFee,
                  [['send', 'update: name-a', zero, -firstFee]])
    self.checkTx (2, updA, zero, -updFee,
                  [['send', 'update: name-a', zero, -updFee]])

    # Send a name from 1 to 2 by firstupdate and update.
    addrB = self.nodes[3].getnewaddress ()
    newB = self.nodes[2].name_new ("name-b")
    newC = self.nodes[2].name_new ("name-c")
    self.generate (0, 5)
    self.checkBalances (2 * newFee)
    firstB = self.firstupdateName (2, "name-b", newB, "value", addrB)
    firstC = self.firstupdateName (2, "name-c", newC, "value")
    self.generate (0, 10)
    self.checkBalances (2 * firstFee)
    updC = self.nodes[2].name_update ("name-c", "new value", addrB)
    self.generate (0, 1)
    self.checkBalances (updFee)

    # Check the receiving transactions on B.
    self.checkTx (3, firstB, zero, None,
                  [['receive', 'update: name-b', zero, None]])
    self.checkTx (3, updC, zero, None,
                  [['receive', 'update: name-c', zero, None]])

    # Use the rawtx API to build a simultaneous name update and currency send.
    # This is done as an atomic name trade.  Note, though, that the
    # logic is a bit confused by "coin join" transactions and thus
    # possibly not exactly what one would expect.

    price = Decimal ("1.0")
    txid = self.atomicTrade ("name-a", "enjoy", price, 2, 3)
    self.generate (0, 1)

    self.checkBalances (-price, price)
    self.checkTx (2, txid, price, None,
                  [['receive', None, price, None]])
    self.checkTx (3, txid, -price, zero,
                  [['send', None, -price, zero],
                   ['send', 'update: name-a', zero, zero]])

    # Test sendtoname RPC command.

    addrDest = self.nodes[2].getnewaddress ()
    newDest = self.nodes[0].name_new ("destination")
    self.generate (0, 5)
    self.firstupdateName (0, "destination", newDest, "value", addrDest)
    self.generate (0, 10)
    self.checkName (3, "destination", "value", None, False)

    try:
      self.nodes[3].sendtoname ("non-existant", 10)
      raise AssertionError ("sendtoname allowed to non-existant name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -5)

    self.nodes[3].sendtoname ("destination", 10)
    self.generate (0, 1)
    self.checkBalances (-10, 10 + txFee)

    self.nodes[3].sendtoname ("destination", 10, "foo", "bar", True)
    self.generate (0, 1)
    self.checkBalances (-10 + txFee, 10)

    self.generate (0, 30)
    self.checkName (3, "destination", "value", None, True)
    try:
      self.nodes[3].sendtoname ("destination", 10)
      raise AssertionError ("sendtoname allowed to expired name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -5)
コード例 #11
0
    def run_test(self):
        NameTestFramework.run_test(self)

        # Mine a block so that we're no longer in initial download.
        self.generate(3, 1)

        # Initially, all should be empty.
        assert_equal(self.nodes[0].name_scan(), [])
        assert_equal(self.nodes[0].name_scan("foo", 10), [])
        assert_equal(self.nodes[0].name_filter(), [])
        assert_equal(self.nodes[0].name_filter("", 0, 0, 0, "stat"), {
            "blocks": 201,
            "count": 0
        })

        # Register some names with various data, heights and expiration status.
        # Using both "aa" and "b" ensures that we can also check for the expected
        # comparison order between string length and lexicographic ordering.

        newA = self.nodes[0].name_new("a")
        newAA = self.nodes[0].name_new("aa")
        newB = self.nodes[1].name_new("b")
        newC = self.nodes[2].name_new("c")
        self.generate(3, 15)

        self.firstupdateName(0, "a", newA, "wrong value")
        self.firstupdateName(0, "aa", newAA, "value aa")
        self.firstupdateName(1, "b", newB, "value b")
        self.generate(3, 15)
        self.firstupdateName(2, "c", newC, "value c")
        self.nodes[0].name_update("a", "value a")
        self.generate(3, 20)

        # Check the expected name_scan data values.
        scan = self.nodes[3].name_scan()
        assert_equal(len(scan), 4)
        self.checkNameData(scan[0], "a", "value a", 11, False)
        self.checkNameData(scan[1], "b", "value b", -4, True)
        self.checkNameData(scan[2], "c", "value c", 11, False)
        self.checkNameData(scan[3], "aa", "value aa", -4, True)

        # Check for expected names in various name_scan calls.
        self.checkList(self.nodes[3].name_scan(), ["a", "b", "c", "aa"])
        self.checkList(self.nodes[3].name_scan("", 0), [])
        self.checkList(self.nodes[3].name_scan("", -1), [])
        self.checkList(self.nodes[3].name_scan("b"), ["b", "c", "aa"])
        self.checkList(self.nodes[3].name_scan("zz"), [])
        self.checkList(self.nodes[3].name_scan("", 2), ["a", "b"])
        self.checkList(self.nodes[3].name_scan("b", 1), ["b"])

        # Check the expected name_filter data values.
        scan = self.nodes[3].name_scan()
        assert_equal(len(scan), 4)
        self.checkNameData(scan[0], "a", "value a", 11, False)
        self.checkNameData(scan[1], "b", "value b", -4, True)
        self.checkNameData(scan[2], "c", "value c", 11, False)
        self.checkNameData(scan[3], "aa", "value aa", -4, True)

        # Check for expected names in various name_filter calls.
        height = self.nodes[3].getblockcount()
        self.checkList(self.nodes[3].name_filter(), ["a", "b", "c", "aa"])
        self.checkList(self.nodes[3].name_filter("[ac]"), ["a", "c", "aa"])
        self.checkList(self.nodes[3].name_filter("", 10), [])
        self.checkList(self.nodes[3].name_filter("", 30), ["a", "c"])
        self.checkList(self.nodes[3].name_filter("", 0, 0, 0),
                       ["a", "b", "c", "aa"])
        self.checkList(self.nodes[3].name_filter("", 0, 0, 1), ["a"])
        self.checkList(self.nodes[3].name_filter("", 0, 1, 4),
                       ["b", "c", "aa"])
        self.checkList(self.nodes[3].name_filter("", 0, 4, 4), [])
        assert_equal(self.nodes[3].name_filter("", 30, 0, 0, "stat"), {
            "blocks": height,
            "count": 2
        })

        # Check test for "stat" argument.
        try:
            self.nodes[3].name_filter("", 0, 0, 0, "string")
            raise AssertionError("wrong check for 'stat' argument")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -8)
コード例 #12
0
    def run_test(self):
        NameTestFramework.run_test(self)

        # Construct a 2-of-2 multisig address shared between two nodes.
        pubkeyA = self.getNewPubkey(0)
        pubkeyB = self.getNewPubkey(1)
        p2sh = self.nodes[0].addmultisigaddress(2, [pubkeyA, pubkeyB])
        p2sh_ = self.nodes[1].addmultisigaddress(2, [pubkeyA, pubkeyB])
        assert_equal(p2sh, p2sh_)

        # Register a new name to that address.
        new = self.nodes[0].name_new("name")
        self.generate(0, 10)
        self.firstupdateName(0, "name", new, "value", p2sh)
        self.generate(1, 5)
        data = self.checkName(2, "name", "value", None, False)
        assert_equal(data['address'], p2sh)

        # Straight-forward name updating should fail (for both nodes).
        try:
            self.nodes[0].name_update("name", "new value")
            raise AssertionError("name_update allowed from single node")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)
        try:
            self.nodes[1].name_update("name", "new value")
            raise AssertionError("name_update allowed from single node")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -4)

        # Find some other input to add as fee.
        unspents = self.nodes[0].listunspent()
        assert len(unspents) > 0
        feeInput = unspents[0]
        changeAddr = self.nodes[0].getnewaddress()
        changeAmount = feeInput['amount'] - Decimal("0.01")

        # Construct the name update as raw transaction.
        addr = self.nodes[2].getnewaddress()
        inputs = [{"txid": data['txid'], "vout": data['vout']}, feeInput]
        outputs = {changeAddr: changeAmount}
        op = {
            "op": "name_update",
            "name": "name",
            "value": "it worked",
            "address": addr
        }
        txRaw = self.nodes[3].createrawtransaction(inputs, outputs, op)

        # Sign it partially.
        partial = self.nodes[0].signrawtransaction(txRaw)
        assert not partial['complete']
        try:
            self.nodes[2].sendrawtransaction(partial['hex'])
            raise AssertionError("incomplete transaction accepted")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -26)

        # Sign it fully and transmit it.
        signed = self.nodes[1].signrawtransaction(partial['hex'])
        assert signed['complete']
        tx = signed['hex']

        # Manipulate the signature to invalidate it.  This checks whether or
        # not the OP_MULTISIG is actually verified (vs just the script hash
        # compared to the redeem script).
        txData = bytearray(binascii.unhexlify(tx))
        txData[44] = (txData[44] + 10) % 256
        txManipulated = binascii.hexlify(txData)

        # Send the tx.  The manipulation should be caught (independently of
        # when strict P2SH checks are enabled, since they are enforced
        # mandatorily in the mempool).
        try:
            self.nodes[2].sendrawtransaction(txManipulated)
            raise AssertionError("manipulated signature tx accepted")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -26)
        self.nodes[2].sendrawtransaction(tx)
        self.generate(3, 1)

        # Check that it was transferred correctly.
        self.checkName(3, "name", "it worked", None, False)
        self.nodes[2].name_update("name", "changed")
        self.generate(3, 1)
        self.checkName(3, "name", "changed", None, False)
コード例 #13
0
ファイル: game_basicnames.py プロジェクト: fsb4000/huntercore
  def run_test (self):
    NameTestFramework.run_test (self)

    # Perform some invalid name_new's and check for the corresponding
    # error messages.
    invalids = ["x" * 11, "", " abc", "abc ", "abc  abc", "a+b"]
    for nm in invalids:
      try:
        self.nodes[0].name_new (nm)
        raise AssertionError ("invalid name not recognised by name_new")
      except JSONRPCException as exc:
        assert_equal (exc.error['code'], -8)

    # On the other hand, these names should all be allowed.  We do not
    # finalise the registration, just make sure that the same test that
    # failed before now succeeds.
    valids = ["x" * 10, "x", "abc def_01", "AB CD-EF"]
    for nm in valids:
      self.nodes[0].name_new (nm)

    # Verify that our name is not yet there.
    testname = "foobar"
    new = self.nodes[0].name_new (testname)
    self.generate (0, 2)
    try:
      self.nodes[0].name_show (testname)
      raise AssertionError ("name_show succeeded for non-existing name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -4)
    try:
      self.nodes[0].game_getplayerstate (testname)
      raise AssertionError ("getplayerstate succeeded for non-existing name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -5)
    state = self.nodes[0].game_getstate ()
    assert_equal (state['players'], {})
    assert_equal ([], self.nodes[0].name_list ())

    # Register the player and verify that it appears on the map.
    self.firstupdateName (0, testname, new, '{"color":0}')
    self.sync_all ()
    self.generate (1, 1)
    self.checkName (2, testname, '{"color":0}', False)
    arr = self.nodes[0].name_list ()
    assert_equal (1, len (arr))
    self.checkNameData (arr[0], testname, '{"color":0}', False)
    assert_equal ([], self.nodes[1].name_list ())
    dat = self.nodes[2].game_getplayerstate (testname)
    state = self.nodes[2].game_getstate ()
    assert_equal (state['players'], {testname: dat})

    # Issue a move command.  Wait long enough for the other hunters
    # to be killed in spawn.
    self.nodes[0].name_update (testname, '{"0":{"wp":[2,2]}}')
    self.sync_all ()
    self.generate (1, 35)

    # Verify that the player is at the position we expect it to be.
    dat = self.nodes[2].game_getplayerstate (testname)
    assert_equal (dat['value'], Decimal('1'))
    assert_equal (dat['0']['x'], 2)
    assert_equal (dat['0']['y'], 2)

    # Check that registering another player of this name is not possible.
    new = self.nodes[1].name_new (testname)
    self.generate (1, 2)
    try:
      self.firstupdateName (1, testname, new, '{"color":0}')
      raise AssertionError ("reregistered existing name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -25)

    # Kill the player on the map.
    self.nodes[0].name_update (testname, '{"0":{"destruct":true}}')
    self.generate (0, 1)
    self.checkName (2, testname, None, True)
    arr = self.nodes[0].name_list ()
    assert_equal (1, len (arr))
    self.checkNameData (arr[0], testname, None, True)
    state = self.nodes[2].game_getstate ()
    assert_equal (state['players'], {})
    found = False
    for sq in state['loot']:
      if (sq['x'], sq['y']) == (2, 2):
        found = True
        assert_equal (sq['amount'], Decimal('0.96'))
    assert found

    # Now we can register another one with the same name.
    self.firstupdateName (1, testname, new, '{"color":0}')
    self.generate (1, 1)
    self.checkName (2, testname, '{"color":0}', False)
    dat = self.nodes[2].game_getplayerstate (testname)
    state = self.nodes[2].game_getstate ()
    assert_equal (state['players'], {testname: dat})

    # The old wallet should still list the dead entry.
    arr = self.nodes[0].name_list ()
    assert_equal (1, len (arr))
    self.checkNameData (arr[0], testname, None, True)

    # Also perform a new-style name_register registration.
    self.nodes[2].name_register ("newstyle", '{"color":1}')
    self.generate (0, 1)
    self.checkName (3, "newstyle", '{"color":1}', False)
    dat = self.nodes[3].game_getplayerstate ("newstyle")
    state = self.nodes[3].game_getstate ()
    assert_equal (len (state['players']), 2)
    assert_equal (state['players']['newstyle'], dat)

    # Transfer the name and check name_list afterwards.
    addr = self.nodes[1].getnewaddress ()
    self.nodes[2].name_update ("newstyle", '{}', addr)
    self.generate (0, 1)
    self.checkName (3, "newstyle", '{}', False)
    arr = self.nodes[1].name_list ()
    assert_equal (2, len (arr))
    self.checkNameData (arr[0], testname, '{"color":0}', False)
    self.checkNameData (arr[1], "newstyle", '{}', False)
    assert not arr[1]['transferred']
    arr = self.nodes[2].name_list ()
    assert_equal (1, len (arr))
    self.checkNameData (arr[0], "newstyle", '{}', False)
    assert arr[0]['transferred']

    # Check listtransactions for the transferred name.
    tx = self.nodes[1].listtransactions ("*", 1)
    assert_equal ("receive", tx[0]['category'])
    assert_equal ("update: newstyle", tx[0]['name'])
    tx = self.nodes[2].listtransactions ("*", 1)
    assert_equal ("send", tx[0]['category'])
    assert_equal ("update: newstyle", tx[0]['name'])

    # Kill both names and verify that name_list handles that.
    self.nodes[1].name_update (testname, '{"0":{"destruct":true}}')
    self.nodes[1].name_update ("newstyle", '{"0":{"destruct":true}}')
    self.generate (0, 1)
    self.checkName (3, testname, None, True)
    self.checkName (3, "newstyle", None, True)
    arr = self.nodes[1].name_list ()
    assert_equal (2, len (arr))
    self.checkNameData (arr[0], testname, None, True)
    self.checkNameData (arr[1], "newstyle", None, True)
コード例 #14
0
  def run_test (self):
    NameTestFramework.run_test (self)

    # Register a name that can then be update'd in the mempool.
    newData = self.nodes[1].name_new ("a")
    self.generate (0, 10)
    self.firstupdateName (1, "a", newData, "old-value-a")
    self.generate (0, 10)

    # Start a new name registration so we can first_update it.
    newData = self.nodes[2].name_new ("b")
    self.generate (0, 15)

    # Perform the unconfirmed updates.  Include a currency transaction
    # and a name_new to check that those are not shown.
    txa = self.nodes[1].name_update ("a", "value-a")
    txb = self.firstupdateName (2, "b", newData, "value-b")
    addrC = self.nodes[3].getnewaddress ()
    self.nodes[2].sendtoaddress (addrC, 1)
    newData = self.nodes[3].name_new ("c")

    # Check that name_show still returns the old value.
    self.checkName (0, "a", "old-value-a", None, False)

    # Check sizes of mempool against name_pending.
    self.sync_all ('mempool')
    mempool = self.nodes[0].getrawmempool ()
    assert_equal (len (mempool), 4)
    pending = self.nodes[0].name_pending ()
    assert_equal (len (pending), 2)

    # Check result of full name_pending (called above).
    for op in pending:
      assert op['txid'] in mempool
      assert not op['ismine']
      if op['name'] == 'a':
        assert_equal (op['op'], 'name_update')
        assert_equal (op['value'], 'value-a')
        assert_equal (op['txid'], txa)
      elif op['name'] == 'b':
        assert_equal (op['op'], 'name_firstupdate')
        assert_equal (op['value'], 'value-b')
        assert_equal (op['txid'], txb)
      else:
        assert False

    # Check name_pending with name filter that does not match any name.
    pending = self.nodes[0].name_pending ('does not exist')
    assert_equal (pending, [])

    # Check name_pending with name filter and ismine.
    self.checkPendingName (1, 'a', 'name_update', 'value-a', txa, True)
    self.checkPendingName (2, 'a', 'name_update', 'value-a', txa, False)

    # Mine a block and check that all mempool is cleared.
    self.generate (0, 1)
    assert_equal (self.nodes[3].getrawmempool (), [])
    assert_equal (self.nodes[3].name_pending (), [])

    # Send a name and check that ismine is handled correctly.
    tx = self.nodes[1].name_update ('a', 'sent-a', addrC)
    self.sync_all ('mempool')
    self.checkPendingName (1, 'a', 'name_update', 'sent-a', tx, False)
    self.checkPendingName (3, 'a', 'name_update', 'sent-a', tx, True)
コード例 #15
0
    def run_test(self):
        NameTestFramework.run_test(self)

        # Start the registration of two names which will be used.  name-long
        # will expire and be reregistered on the short chain, which will be
        # undone with the reorg.  name-short will be updated before expiration
        # on the short chain, but this will be rerolled and the name expire
        # instead on the long chain.  Check that the mempool and the UTXO set
        # behave as they should.
        newLong = self.nodes[0].name_new("name-long")
        newLong2 = self.nodes[3].name_new("name-long")
        newShort = self.nodes[3].name_new("name-short")
        self.generate(1, 12)

        # Register the names.  name-long should expire one block before
        # name-short, so that the situation described above works out.
        updLong = self.firstupdateName(0, "name-long", newLong, "value")
        self.generate(1, 2)
        updShort = self.firstupdateName(3, "name-short", newShort, "value")
        self.generate(1, 27)
        self.checkName(1, "name-long", "value", 2, False)
        self.checkName(1, "name-short", "value", 4, False)

        # Check that the UTXO entries are there.
        self.checkUTXO(1, "name-long", True)
        self.checkUTXO(1, "name-short", True)

        # Split the network.
        self.split_network()

        # Let name-long expire on the short chain.
        self.generate(2, 2)
        self.checkName(2, "name-long", "value", 0, True)
        self.checkName(2, "name-short", "value", 2, False)
        self.checkUTXO(2, "name-long", False)
        self.checkUTXO(2, "name-short", True)

        # Snatch up name-long and update name-short just-in-time.  Note that
        # "just-in-time" is "expires_in == 2", since when creating the block,
        # it will be "expires_in == 1" already!
        updLong2 = self.firstupdateName(3, "name-long", newLong2, "value 2")
        renewShort = self.nodes[3].name_update("name-short", "renewed")
        self.generate(2, 1)
        self.checkName(2, "name-long", "value 2", 30, False)
        self.checkName(2, "name-short", "renewed", 30, False)
        self.checkNameHistory(2, "name-long", ["value", "value 2"])
        self.checkNameHistory(2, "name-short", ["value", "renewed"])

        # Create a longer chain on the other part of the network.  Let name-short
        # expire there but renew name-long instead.
        self.nodes[0].name_update("name-long", "renewed")
        self.generate(1, 5)
        self.checkName(1, "name-long", "renewed", 26, False)
        self.checkName(1, "name-short", "value", -1, True)
        self.checkNameHistory(1, "name-long", ["value", "renewed"])
        self.checkNameHistory(1, "name-short", ["value"])
        self.checkUTXO(1, "name-long", True)
        self.checkUTXO(1, "name-short", False)

        # Join the network and let the long chain prevail.  This should
        # completely revoke all changes on the short chain, including
        # the mempool (since all tx there are conflicts with name expirations).
        assert self.nodes[1].getblockcount() > self.nodes[2].getblockcount()
        self.join_network()

        # Test the expected situation of the long chain.
        self.checkName(2, "name-long", "renewed", 26, False)
        self.checkName(2, "name-short", "value", -1, True)
        self.checkNameHistory(2, "name-long", ["value", "renewed"])
        self.checkNameHistory(2, "name-short", ["value"])
        self.checkUTXO(2, "name-long", True)
        self.checkUTXO(2, "name-short", False)

        # Check that the conflicting tx's are marked in the wallet
        # as conflicts and that they got removed from the mempool.
        assert_equal(self.nodes[0].getrawmempool(), [])
        assert_equal(self.nodes[3].getrawmempool(), [])
        data = self.nodes[3].gettransaction(updLong2)
        assert_equal(data['confirmations'], -1)
        data = self.nodes[3].gettransaction(renewShort)
        assert_equal(data['confirmations'], -1)
コード例 #16
0
ファイル: name_expiration.py プロジェクト: IXCoin-Dev/ixcore
  def run_test (self):
    NameTestFramework.run_test (self)

    # Start the registration of two names which will be used.  name-long
    # will expire and be reregistered on the short chain, which will be
    # undone with the reorg.  name-short will be updated before expiration
    # on the short chain, but this will be rerolled and the name expire
    # instead on the long chain.  Check that the mempool and the UTXO set
    # behave as they should.
    newLong = self.nodes[0].name_new ("name-long")
    newLong2 = self.nodes[3].name_new ("name-long")
    newShort = self.nodes[3].name_new ("name-short")
    self.generate (1, 12)

    # Register the names.  name-long should expire one block before
    # name-short, so that the situation described above works out.
    updLong = self.firstupdateName (0, "name-long", newLong, "value")
    self.generate (1, 2)
    updShort = self.firstupdateName (3, "name-short", newShort, "value")
    self.generate (1, 27)
    self.checkName (1, "name-long", "value", 2, False)
    self.checkName (1, "name-short", "value", 4, False)

    # Check that the UTXO entries are there.
    self.checkUTXO (1, "name-long", True)
    self.checkUTXO (1, "name-short", True)

    # Split the network.
    self.split_network ()

    # Let name-long expire on the short chain.
    self.generate (2, 2)
    self.checkName (2, "name-long", "value", 0, True)
    self.checkName (2, "name-short", "value", 2, False)
    self.checkUTXO (2, "name-long", False)
    self.checkUTXO (2, "name-short", True)

    # Snatch up name-long and update name-short just-in-time.  Note that
    # "just-in-time" is "expires_in == 2", since when creating the block,
    # it will be "expires_in == 1" already!
    updLong2 = self.firstupdateName (3, "name-long", newLong2, "value 2")
    renewShort = self.nodes[3].name_update ("name-short", "renewed")
    self.generate (2, 1)
    self.checkName (2, "name-long", "value 2", 30, False)
    self.checkName (2, "name-short", "renewed", 30, False)
    self.checkNameHistory (2, "name-long", ["value", "value 2"])
    self.checkNameHistory (2, "name-short", ["value", "renewed"])

    # Create a longer chain on the other part of the network.  Let name-short
    # expire there but renew name-long instead.
    self.nodes[0].name_update ("name-long", "renewed")
    self.generate (1, 5)
    self.checkName (1, "name-long", "renewed", 26, False)
    self.checkName (1, "name-short", "value", -1, True)
    self.checkNameHistory (1, "name-long", ["value", "renewed"])
    self.checkNameHistory (1, "name-short", ["value"])
    self.checkUTXO (1, "name-long", True)
    self.checkUTXO (1, "name-short", False)

    # Join the network and let the long chain prevail.  This should
    # completely revoke all changes on the short chain, including
    # the mempool (since all tx there are conflicts with name expirations).
    assert self.nodes[1].getblockcount () > self.nodes[2].getblockcount ()
    self.join_network ()

    # Test the expected situation of the long chain.
    self.checkName (2, "name-long", "renewed", 26, False)
    self.checkName (2, "name-short", "value", -1, True)
    self.checkNameHistory (2, "name-long", ["value", "renewed"])
    self.checkNameHistory (2, "name-short", ["value"])
    self.checkUTXO (2, "name-long", True)
    self.checkUTXO (2, "name-short", False)

    # Check that the conflicting tx's are marked in the wallet
    # as conflicts and that they got removed from the mempool.
    assert_equal (self.nodes[0].getrawmempool (), [])
    assert_equal (self.nodes[3].getrawmempool (), [])
    data = self.nodes[3].gettransaction (updLong2)
    assert_equal (data['confirmations'], -1)
    data = self.nodes[3].gettransaction (renewShort)
    assert_equal (data['confirmations'], -1)
コード例 #17
0
ファイル: name_wallet.py プロジェクト: deLeewit/namecoin-core
  def run_test (self):
    NameTestFramework.run_test (self)
    
    # Note that the next 50 maturing blocks will be for nodes 0 and 1.
    # Thus we use 2 and 3 for the tests, because their balance
    # will stay constant over time except for our explicit transactions.

    self.checkBalances ()

    # Register and update a name.  Check changes to the balance.
    newA = self.nodes[2].name_new ("name-a")
    newFee = self.getFee (2, newA[0], nameFee)
    self.generate (0, 5)
    self.checkBalances (newFee)
    firstA = self.firstupdateName (2, "name-a", newA, "value")
    firstFee = self.getFee (2, firstA)
    self.generate (0, 10)
    self.checkBalances (firstFee)
    updA = self.nodes[2].name_update ("name-a", "new value")
    updFee = self.getFee (2, updA)
    self.generate (0, 1)
    self.checkBalances (updFee)

    # Check the transactions.
    self.checkTx (2, newA[0], zero, -newFee,
                  [['send', 'new', zero, -newFee]])
    self.checkTx (2, firstA, zero, -firstFee,
                  [['send', 'update: name-a', zero, -firstFee]])
    self.checkTx (2, updA, zero, -updFee,
                  [['send', 'update: name-a', zero, -updFee]])

    # Send a name from 1 to 2 by firstupdate and update.
    addrB = self.nodes[3].getnewaddress ()
    newB = self.nodes[2].name_new ("name-b")
    fee = self.getFee (2, newB[0], nameFee)
    newC = self.nodes[2].name_new ("name-c")
    fee += self.getFee (2, newC[0], nameFee)
    self.generate (0, 5)
    self.checkBalances (fee)
    firstB = self.firstupdateName (2, "name-b", newB, "value", addrB)
    fee = self.getFee (2, firstB)
    firstC = self.firstupdateName (2, "name-c", newC, "value")
    fee += self.getFee (2, firstC)
    self.generate (0, 10)
    self.checkBalances (fee)
    updC = self.nodes[2].name_update ("name-c", "new value", addrB)
    fee = self.getFee (2, updC)
    self.generate (0, 1)
    self.checkBalances (fee)

    # Check the receiving transactions on B.
    self.checkTx (3, firstB, zero, None,
                  [['receive', 'update: name-b', zero, None]])
    self.checkTx (3, updC, zero, None,
                  [['receive', 'update: name-c', zero, None]])

    # Use the rawtx API to build a simultaneous name update and currency send.
    # This is done as an atomic name trade.  Note, though, that the
    # logic is a bit confused by "coin join" transactions and thus
    # possibly not exactly what one would expect.

    price = Decimal ("1.0")
    fee = Decimal ("0.01")
    txid = self.atomicTrade ("name-a", "enjoy", price, fee, 2, 3)
    self.generate (0, 1)

    self.checkBalances (-price, price + fee)
    self.checkTx (2, txid, price, None,
                  [['receive', "none", price, None]])
    self.checkTx (3, txid, -price, -fee,
                  [['send', "none", -price, -fee],
                   ['send', 'update: name-a', zero, -fee]])

    # Test sendtoname RPC command.

    addrDest = self.nodes[2].getnewaddress ()
    newDest = self.nodes[0].name_new ("destination")
    self.generate (0, 5)
    self.firstupdateName (0, "destination", newDest, "value", addrDest)
    self.generate (0, 10)
    self.checkName (3, "destination", "value", None, False)

    try:
      self.nodes[3].sendtoname ("non-existant", 10)
      raise AssertionError ("sendtoname allowed to non-existant name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -5)

    txid = self.nodes[3].sendtoname ("destination", 10)
    fee = self.getFee (3, txid)
    self.generate (0, 1)
    self.checkBalances (-10, 10 + fee)

    txid = self.nodes[3].sendtoname ("destination", 10, "foo", "bar", True)
    fee = self.getFee (3, txid)
    self.generate (0, 1)
    self.checkBalances (-10 + fee, 10)

    self.generate (0, 30)
    self.checkName (3, "destination", "value", None, True)
    try:
      self.nodes[3].sendtoname ("destination", 10)
      raise AssertionError ("sendtoname allowed to expired name")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -5)
コード例 #18
0
ファイル: name_reorg.py プロジェクト: kha0S/namecore
    def run_test(self):
        NameTestFramework.run_test(self)

        # Register a name prior to forking the chain.  This is used
        # to test unrolling of updates (as opposed to registrations).
        newA = self.nodes[3].name_new("a")
        newBshort = self.nodes[3].name_new("b")
        newBlong = self.nodes[0].name_new("b")
        newC = self.nodes[3].name_new("c")
        self.generate(0, 10)
        self.firstupdateName(3, "a", newA, "initial value")
        self.generate(0, 5)

        # Split the network.
        self.split_network()

        # Build a long chain that registers "b" (to clash with
        # the same registration on the short chain).
        self.generate(0, 2)
        self.firstupdateName(0, "b", newBlong, "b long")
        self.generate(0, 2)
        self.checkName(0, "a", "initial value", None, False)
        self.checkName(0, "b", "b long", None, False)
        self.checkNameHistory(1, "a", ["initial value"])
        self.checkNameHistory(1, "b", ["b long"])

        # Build a short chain with an update to "a" and registrations.
        self.generate(3, 1)
        txidB = self.firstupdateName(3, "b", newBshort, "b short")
        self.firstupdateName(3, "c", newC, "c registered")
        self.nodes[3].name_update("a", "changed value")
        self.generate(3, 1)
        self.checkName(3, "a", "changed value", None, False)
        self.checkName(3, "b", "b short", None, False)
        self.checkName(3, "c", "c registered", None, False)
        self.checkNameHistory(2, "a", ["initial value", "changed value"])
        self.checkNameHistory(2, "b", ["b short"])
        self.checkNameHistory(2, "c", ["c registered"])

        # Join the network and let the long chain prevail.
        self.join_network()
        self.checkName(3, "a", "initial value", None, False)
        self.checkName(3, "b", "b long", None, False)
        self.checkNameHistory(2, "a", ["initial value"])
        self.checkNameHistory(2, "b", ["b long"])
        try:
            self.nodes[3].name_show("c")
            raise AssertionError("'c' still registered after reorg")
        except JSONRPCException as exc:
            assert_equal(exc.error["code"], -4)
        try:
            self.nodes[2].name_history("c")
            raise AssertionError("'c' still registered after reorg")
        except JSONRPCException as exc:
            assert_equal(exc.error["code"], -4)

        # Mine another block.  This should at least perform the
        # non-conflicting transactions.  It is done on node 3 so
        # that these tx are actually in the mempool.
        self.generate(3, 1, False)
        self.checkName(3, "a", "changed value", None, False)
        self.checkName(3, "b", "b long", None, False)
        self.checkName(3, "c", "c registered", None, False)
        self.checkNameHistory(2, "a", ["initial value", "changed value"])
        self.checkNameHistory(2, "b", ["b long"])
        self.checkNameHistory(2, "c", ["c registered"])

        # Check that the conflicting tx got pruned from the mempool properly
        # and is marked as conflicted in the wallet.
        assert_equal(self.nodes[0].getrawmempool(), [])
        assert_equal(self.nodes[3].getrawmempool(), [])
        data = self.nodes[3].gettransaction(txidB)
        assert_equal(data["confirmations"], -1)
コード例 #19
0
ファイル: name_pending.py プロジェクト: zebbra2014/namecore
    def run_test(self):
        NameTestFramework.run_test(self)

        # Register a name that can then be update'd in the mempool.
        newData = self.nodes[1].name_new("a")
        self.generate(0, 10)
        self.firstupdateName(1, "a", newData, "old-value-a")
        self.generate(0, 10)

        # Start a new name registration so we can first_update it.
        newData = self.nodes[2].name_new("b")
        self.generate(0, 15)

        # Perform the unconfirmed updates.  Include a currency transaction
        # and a name_new to check that those are not shown.
        txa = self.nodes[1].name_update("a", "value-a")
        txb = self.firstupdateName(2, "b", newData, "value-b")
        addrC = self.nodes[3].getnewaddress()
        self.nodes[2].sendtoaddress(addrC, 1)
        newData = self.nodes[3].name_new("c")

        # Check that name_show still returns the old value.
        self.checkName(0, "a", "old-value-a", None, False)

        # Check sizes of mempool against name_pending.
        self.sync_all('mempool')
        mempool = self.nodes[0].getrawmempool()
        assert_equal(len(mempool), 4)
        pending = self.nodes[0].name_pending()
        assert_equal(len(pending), 2)

        # Check result of full name_pending (called above).
        for op in pending:
            assert op['txid'] in mempool
            assert not op['ismine']
            if op['name'] == 'a':
                assert_equal(op['op'], 'name_update')
                assert_equal(op['value'], 'value-a')
                assert_equal(op['txid'], txa)
            elif op['name'] == 'b':
                assert_equal(op['op'], 'name_firstupdate')
                assert_equal(op['value'], 'value-b')
                assert_equal(op['txid'], txb)
            else:
                assert False

        # Check name_pending with name filter that does not match any name.
        pending = self.nodes[0].name_pending('does not exist')
        assert_equal(pending, [])

        # Check name_pending with name filter and ismine.
        self.checkPendingName(1, 'a', 'name_update', 'value-a', txa, True)
        self.checkPendingName(2, 'a', 'name_update', 'value-a', txa, False)

        # Mine a block and check that all mempool is cleared.
        self.generate(0, 1)
        assert_equal(self.nodes[3].getrawmempool(), [])
        assert_equal(self.nodes[3].name_pending(), [])

        # Send a name and check that ismine is handled correctly.
        tx = self.nodes[1].name_update('a', 'sent-a', addrC)
        self.sync_all('mempool')
        self.checkPendingName(1, 'a', 'name_update', 'sent-a', tx, False)
        self.checkPendingName(3, 'a', 'name_update', 'sent-a', tx, True)
コード例 #20
0
  def run_test (self):
    NameTestFramework.run_test (self)

    # Mine a block so that we're no longer in initial download.
    self.generate (3, 1)

    # Initially, all should be empty.
    assert_equal (self.nodes[0].name_scan (), [])
    assert_equal (self.nodes[0].name_scan ("foo", 10), [])
    assert_equal (self.nodes[0].name_filter (), [])
    assert_equal (self.nodes[0].name_filter ("", 0, 0, 0, "stat"),
                  {"blocks": 201,"count": 0})

    # Register some names with various data, heights and expiration status.
    # Using both "aa" and "b" ensures that we can also check for the expected
    # comparison order between string length and lexicographic ordering.

    newA = self.nodes[0].name_new ("a")
    newAA = self.nodes[0].name_new ("aa")
    newB = self.nodes[1].name_new ("b")
    newC = self.nodes[2].name_new ("c")
    self.generate (3, 15)

    self.firstupdateName (0, "a", newA, "wrong value")
    self.firstupdateName (0, "aa", newAA, "value aa")
    self.firstupdateName (1, "b", newB, "value b")
    self.generate (3, 15)
    self.firstupdateName (2, "c", newC, "value c")
    self.nodes[0].name_update ("a", "value a")
    self.generate (3, 20)

    # Check the expected name_scan data values.
    scan = self.nodes[3].name_scan ()
    assert_equal (len (scan), 4)
    self.checkNameData (scan[0], "a", "value a", 11, False)
    self.checkNameData (scan[1], "b", "value b", -4, True)
    self.checkNameData (scan[2], "c", "value c", 11, False)
    self.checkNameData (scan[3], "aa", "value aa", -4, True)

    # Check for expected names in various name_scan calls.
    self.checkList (self.nodes[3].name_scan (), ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_scan ("", 0), [])
    self.checkList (self.nodes[3].name_scan ("", -1), [])
    self.checkList (self.nodes[3].name_scan ("b"), ["b", "c", "aa"])
    self.checkList (self.nodes[3].name_scan ("zz"), [])
    self.checkList (self.nodes[3].name_scan ("", 2), ["a", "b"])
    self.checkList (self.nodes[3].name_scan ("b", 1), ["b"])

    # Check the expected name_filter data values.
    scan = self.nodes[3].name_scan ()
    assert_equal (len (scan), 4)
    self.checkNameData (scan[0], "a", "value a", 11, False)
    self.checkNameData (scan[1], "b", "value b", -4, True)
    self.checkNameData (scan[2], "c", "value c", 11, False)
    self.checkNameData (scan[3], "aa", "value aa", -4, True)

    # Check for expected names in various name_filter calls.
    height = self.nodes[3].getblockcount ()
    self.checkList (self.nodes[3].name_filter (), ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("[ac]"), ["a", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 10), [])
    self.checkList (self.nodes[3].name_filter ("", 30), ["a", "c"])
    self.checkList (self.nodes[3].name_filter ("", 0, 0, 0),
                    ["a", "b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 0, 0, 1), ["a"])
    self.checkList (self.nodes[3].name_filter ("", 0, 1, 4), ["b", "c", "aa"])
    self.checkList (self.nodes[3].name_filter ("", 0, 4, 4), [])
    assert_equal (self.nodes[3].name_filter ("", 30, 0, 0, "stat"),
                  {"blocks": height, "count": 2})

    # Check test for "stat" argument.
    try:
      self.nodes[3].name_filter ("", 0, 0, 0, "string")
      raise AssertionError ("wrong check for 'stat' argument")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)
コード例 #21
0
ファイル: name_list.py プロジェクト: zebbra2014/namecore
    def run_test(self):
        NameTestFramework.run_test(self)

        assert_equal(self.nodes[0].name_list(), [])
        assert_equal(self.nodes[1].name_list(), [])

        newA = self.nodes[0].name_new("name-a")
        newB = self.nodes[1].name_new("name-b")
        self.generate(0, 10)
        self.firstupdateName(0, "name-a", newA, "value-a")
        self.firstupdateName(1, "name-b", newB, "value-b")
        self.generate(1, 5)

        arr = self.nodes[0].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "value-a", False, False)
        arr = self.nodes[1].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-b", "value-b", False, False)

        assert_equal(self.nodes[0].name_list("name-b"), [])
        assert_equal(self.nodes[1].name_list("name-a"), [])

        # Transfer a name away and check that name_list updates accordingly.

        addrB = self.nodes[1].getnewaddress()
        self.nodes[0].name_update("name-a", "enjoy", addrB)
        arr = self.nodes[0].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "value-a", False, False)

        self.generate(0, 1)
        arr = self.nodes[0].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "enjoy", False, True)
        arr = self.nodes[1].name_list()
        assert_equal(len(arr), 2)
        self.checkNameStatus(arr[0], "name-a", "enjoy", False, False)
        self.checkNameStatus(arr[1], "name-b", "value-b", False, False)

        # Updating the name in the new wallet shouldn't change the
        # old wallet's name_list entry.
        self.nodes[1].name_update("name-a", "new value")
        self.generate(0, 1)
        arr = self.nodes[0].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "enjoy", False, True)
        arr = self.nodes[1].name_list("name-a")
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "new value", False, False)

        # Transfer it back and see that it updates in wallet A.
        addrA = self.nodes[0].getnewaddress()
        self.nodes[1].name_update("name-a", "sent", addrA)
        self.generate(0, 1)
        arr = self.nodes[0].name_list()
        assert_equal(len(arr), 1)
        self.checkNameStatus(arr[0], "name-a", "sent", False, False)

        # Let name-b expire.
        self.generate(0, 25)
        arr = self.nodes[1].name_list()
        assert_equal(len(arr), 2)
        self.checkNameStatus(arr[0], "name-a", "sent", False, True)
        self.checkNameStatus(arr[1], "name-b", "value-b", True, False)