示例#1
0
    def setUp(self):
        self.patcher = ScorePatcher(Converter)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + os.urandom(20).hex())
        self.score = Converter(create_db(self.score_address))

        self.owner = Address.from_string("hx" + os.urandom(20).hex())
        self.token = Address.from_string("cx" + os.urandom(20).hex())
        registry = Address.from_string("cx" + os.urandom(20).hex())
        max_conversion_fee = 1000000
        self.initial_connector_token = Address.from_string(
            "cx" + os.urandom(20).hex())
        self.initial_connector_weight = 500000

        with patch_property(IconScoreBase, 'msg', Message(self.owner)):
            self.score.on_install(self.token, registry, max_conversion_fee,
                                  self.initial_connector_token,
                                  self.initial_connector_weight)
            FlexibleTokenController.on_install.assert_called_with(
                self.score, self.token)
            self.score._token.set(self.token)

            self.assertEqual(registry, self.score._registry.get())
            self.assertEqual(registry, self.score._prev_registry.get())
            self.assertEqual(max_conversion_fee,
                             self.score._max_conversion_fee.get())

            self.assertEqual(
                True, self.score._connectors[
                    self.initial_connector_token].is_set.get())
            self.assertEqual(
                self.initial_connector_weight, self.score._connectors[
                    self.initial_connector_token].weight.get())
示例#2
0
    def setUp(self):
        self.patcher = ScorePatcher(TokenHolder)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.token_holder = TokenHolder(create_db(self.score_address))

        self.token_owner = Address.from_string("hx" + "2" * 40)
        with patch_property(IconScoreBase, 'msg', Message(self.token_owner)):
            self.token_holder.on_install()
            Owned.on_install.assert_called_with(self.token_holder)
示例#3
0
    def setUp(self):
        self.patcher = ScorePatcher(Owned)
        self.patcher.start()

        score_address = Address.from_string("cx" + "1" * 40)
        self.score = Owned(create_db(score_address))

        self.sender = Address.from_string("hx" + "2" * 40)
        with patch_property(IconScoreBase, 'msg', Message(self.sender)):
            self.score.on_install()
            self.assertEqual(self.sender, self.score._owner.get())
            self.assertEqual(ZERO_SCORE_ADDRESS, self.score._new_owner.get())
示例#4
0
    def setUp(self):
        self.patcher = ScorePatcher(IcxToken)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.icx_token = IcxToken(create_db(self.score_address))

        self.token_owner = Address.from_string("hx" + "2" * 40)
        with patch_property(IconScoreBase, 'msg', Message(self.token_owner)):
            self.icx_token.on_install()
            IRCToken.on_install.assert_called_with(self.icx_token, 'icx_token',
                                                   'ICX', 0, 18)
            TokenHolder.on_install.assert_called_with(self.icx_token)
    def setUp(self):
        self.patcher = ScorePatcher(IcxToken)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.flexible_token_address = Address.from_string("cx" + "2" * 40)
        self.score = FlexibleTokenController(create_db(self.score_address))

        self.owner = Address.from_string("hx" + "2" * 40)
        with MultiPatch([
            patch_property(IconScoreBase, 'msg', Message(self.owner)),
            patch('contracts.utility.flexible_token_controller.require_valid_address')
        ]) as mocks:
            self.score.on_install(self.flexible_token_address)
            TokenHolder.on_install.assert_called_with(self.score)
            mocks[1].assert_called()
示例#6
0
    def setUp(self):
        self.patcher = ScorePatcher(ScoreRegistry)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.registry_score = ScoreRegistry(create_db(self.score_address))

        self.registry_owner = Address.from_string("hx" + "1" * 40)
        with patch_property(IconScoreBase, 'msg',
                            Message(self.registry_owner)):
            self.registry_score.on_install()
            Owned.on_install.assert_called_with(self.registry_score)

            # success case: when deploy ScoreRegistry, score registry address should be registered by default
            self.assertEqual \
                (self.score_address,
                 self.registry_score._score_address[self.registry_score.SCORE_REGISTRY.encode()])
示例#7
0
    def setUp(self):
        self.patcher = ScorePatcher(Network)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.network_score = Network(create_db(self.score_address))

        self.network_owner = Address.from_string("hx" + "1" * 40)

        self.flexible_token_address_list = [
            Address.from_string("cx" + str(i) * 40) for i in range(0, 3)
        ]
        self.connector_token_list = [
            Address.from_string("cx" + str(i) * 40) for i in range(3, 7)
        ]
        self.icx_token = Address.from_string("cx" + "7" * 40)

        with patch_property(IconScoreBase, 'msg', Message(self.network_owner)):
            self.network_score.on_install()
            TokenHolder.on_install.assert_called_with(self.network_score)
示例#8
0
    def setUp(self):
        self.patcher = ScorePatcher(IRCToken)
        self.patcher.start()

        self.score_address = Address.from_string("cx" + "1" * 40)
        self.irc_token = IRCToken(create_db(self.score_address))
        token_name = "test_token"
        token_symbol = "TST"
        token_supply = 100
        token_decimals = 18

        self.token_owner = Address.from_string("hx" + "2" * 40)

        # failure case: total supply is under 0
        with patch_property(IconScoreBase, 'msg', Message(self.token_owner)):
            invalid_token_supply = -1
            self.assertRaises(RevertException, self.irc_token.on_install,
                              token_name, token_symbol, invalid_token_supply,
                              token_decimals)

        # failure case: decimal is under 0
        with patch_property(IconScoreBase, 'msg', Message(self.token_owner)):
            invalid_token_decimals = -1
            self.assertRaises(RevertException, self.irc_token.on_install,
                              token_name, token_symbol, token_supply,
                              invalid_token_decimals)

        # success case: deploy IRCToken with valid parameters
        with patch_property(IconScoreBase, 'msg', Message(self.token_owner)):
            self.irc_token.on_install(token_name, token_symbol, token_supply,
                                      token_decimals)
            self.assertEqual(token_name, self.irc_token._name.get())
            self.assertEqual(token_symbol, self.irc_token._symbol.get())
            self.assertEqual(token_decimals, self.irc_token._decimals.get())
            self.assertEqual(token_supply * 10**token_decimals,
                             self.irc_token._total_supply.get())
            self.assertEqual(token_supply * 10**token_decimals,
                             self.irc_token._balances[self.token_owner])
示例#9
0
 def setUp(self):
     self.storage = Storage(create_db(Address.from_string("cx" + "1" * 40)))
     self.storage.add_fields([('array_db', ArrayDB, int),
                              ('dict_db', DictDB, int),
                              ('var_db', VarDB, int)])