from xpxchain import client
from xpxchain import models
from tests import harness
from tests import responses


@harness.mocked_http_test_case({
    'clients': (client.ConfigHTTP, client.AsyncConfigHTTP),
    'network_type': models.NetworkType.MIJIN_TEST,
    'tests': [
        {
            'name': 'test_get_config',
            'response': responses.CONFIG["Ok"],
            'params': [100],
            'method': 'get_config',
            'validation': [
                lambda x: (isinstance(x, models.CatapultConfig), True),
                lambda x: (x.height, 245311),
                lambda x: (isinstance(x.network_config, models.Sections), True),
                lambda x: ('network' in x.network_config.sections, True),
                lambda x: ('publicKey' in x.network_config.sections['network'].flds, True),
                lambda x: (x.network_config.sections['network'].flds['publicKey'], '5D3CE4904D04E9FDEB22D4273A960A8F954B9C60D622E2066DAC9B3EA8A943CB'),
                
                lambda x: ('chain' in x.network_config.sections, True),
                lambda x: ('blockGenerationTargetTime' in x.network_config.sections['chain'].flds, True),
                lambda x: ('blockTimeSmoothingFactor' in x.network_config.sections['chain'].flds, True),
                lambda x: ('greedDelta' in x.network_config.sections['chain'].flds, True),
                lambda x: ('greedExponent' in x.network_config.sections['chain'].flds, True),
                lambda x: ('importanceGrouping' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxRollbackBlocks' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxDifficultyBlocks' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxTransactionLifetime' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxBlockFutureTime' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxMosaicAtomicUnits' in x.network_config.sections['chain'].flds, True),
                lambda x: ('totalChainImportance' in x.network_config.sections['chain'].flds, True),
                lambda x: ('minHarvesterBalance' in x.network_config.sections['chain'].flds, True),
                lambda x: ('harvestBeneficiaryPercentage' in x.network_config.sections['chain'].flds, True),
                lambda x: ('blockPruneInterval' in x.network_config.sections['chain'].flds, True),
                lambda x: ('maxTransactionsPerBlock' in x.network_config.sections['chain'].flds, True),
                lambda x: ('enableUnconfirmedTransactionMinFeeValidation' in x.network_config.sections['chain'].flds, True),
                lambda x: (x.network_config.sections['chain'].flds['blockGenerationTargetTime'], '15s'),
                lambda x: (x.network_config.sections['chain'].flds['blockTimeSmoothingFactor'], '3000'),
                lambda x: (x.network_config.sections['chain'].flds['greedDelta'], '0.5'),
                lambda x: (x.network_config.sections['chain'].flds['greedExponent'], '3.2'),
                lambda x: (x.network_config.sections['chain'].flds['importanceGrouping'], '5760'),
                lambda x: (x.network_config.sections['chain'].flds['maxRollbackBlocks'], '360'),
                lambda x: (x.network_config.sections['chain'].flds['maxDifficultyBlocks'], '4'),
                lambda x: (x.network_config.sections['chain'].flds['maxTransactionLifetime'], '24h'),
                lambda x: (x.network_config.sections['chain'].flds['maxBlockFutureTime'], '10s'),
                lambda x: (x.network_config.sections['chain'].flds['maxMosaicAtomicUnits'], '9\'000\'000\'000\'000\'001'),
                lambda x: (x.network_config.sections['chain'].flds['totalChainImportance'], '9\'000\'000\'000\'000\'000'),
                lambda x: (x.network_config.sections['chain'].flds['minHarvesterBalance'], '100\'000\'000\'000'),
                lambda x: (x.network_config.sections['chain'].flds['harvestBeneficiaryPercentage'], '10'),
                lambda x: (x.network_config.sections['chain'].flds['blockPruneInterval'], '360'),
                lambda x: (x.network_config.sections['chain'].flds['maxTransactionsPerBlock'], '200\'000'),
                lambda x: (x.network_config.sections['chain'].flds['enableUnconfirmedTransactionMinFeeValidation'], 'false'),

                lambda x: ('plugin:catapult.plugins.accountlink' in x.network_config.sections, True),
                lambda x: ('dummy' in x.network_config.sections['plugin:catapult.plugins.accountlink'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.accountlink'].flds['dummy'], 'to trigger plugin load'),

                lambda x: ('plugin:catapult.plugins.aggregate' in x.network_config.sections, True),
                lambda x: ('maxTransactionsPerAggregate' in x.network_config.sections['plugin:catapult.plugins.aggregate'].flds, True),
                lambda x: ('maxCosignaturesPerAggregate' in x.network_config.sections['plugin:catapult.plugins.aggregate'].flds, True),
                lambda x: ('enableStrictCosignatureCheck' in x.network_config.sections['plugin:catapult.plugins.aggregate'].flds, True),
                lambda x: ('enableBondedAggregateSupport' in x.network_config.sections['plugin:catapult.plugins.aggregate'].flds, True),
                lambda x: ('maxBondedTransactionLifetime' in x.network_config.sections['plugin:catapult.plugins.aggregate'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.aggregate'].flds['maxTransactionsPerAggregate'], '1\'000'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.aggregate'].flds['maxCosignaturesPerAggregate'], '15'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.aggregate'].flds['enableStrictCosignatureCheck'], 'false'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.aggregate'].flds['enableBondedAggregateSupport'], 'true'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.aggregate'].flds['maxBondedTransactionLifetime'], '48h'),

                lambda x: ('plugin:catapult.plugins.config' in x.network_config.sections, True),
                lambda x: ('maxBlockChainConfigSize' in x.network_config.sections['plugin:catapult.plugins.config'].flds, True),
                lambda x: ('maxSupportedEntityVersionsSize' in x.network_config.sections['plugin:catapult.plugins.config'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.config'].flds['maxBlockChainConfigSize'], '1MB'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.config'].flds['maxSupportedEntityVersionsSize'], '1MB'),

                lambda x: ('plugin:catapult.plugins.contract' in x.network_config.sections, True),
                lambda x: ('minPercentageOfApproval' in x.network_config.sections['plugin:catapult.plugins.contract'].flds, True),
                lambda x: ('minPercentageOfRemoval' in x.network_config.sections['plugin:catapult.plugins.contract'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.contract'].flds['minPercentageOfApproval'], '100'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.contract'].flds['minPercentageOfRemoval'], '66'),

                lambda x: ('plugin:catapult.plugins.lockhash' in x.network_config.sections, True),
                lambda x: ('lockedFundsPerAggregate' in x.network_config.sections['plugin:catapult.plugins.lockhash'].flds, True),
                lambda x: ('maxHashLockDuration' in x.network_config.sections['plugin:catapult.plugins.lockhash'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.lockhash'].flds['lockedFundsPerAggregate'], '10\'000\'000'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.lockhash'].flds['maxHashLockDuration'], '2d'),

                lambda x: ('plugin:catapult.plugins.locksecret' in x.network_config.sections, True),
                lambda x: ('maxSecretLockDuration' in x.network_config.sections['plugin:catapult.plugins.locksecret'].flds, True),
                lambda x: ('minProofSize' in x.network_config.sections['plugin:catapult.plugins.locksecret'].flds, True),
                lambda x: ('maxProofSize' in x.network_config.sections['plugin:catapult.plugins.locksecret'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.locksecret'].flds['maxSecretLockDuration'], '30d'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.locksecret'].flds['minProofSize'], '1'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.locksecret'].flds['maxProofSize'], '1000'),

                lambda x: ('plugin:catapult.plugins.metadata' in x.network_config.sections, True),
                lambda x: ('maxFields' in x.network_config.sections['plugin:catapult.plugins.metadata'].flds, True),
                lambda x: ('maxFieldKeySize' in x.network_config.sections['plugin:catapult.plugins.metadata'].flds, True),
                lambda x: ('maxFieldValueSize' in x.network_config.sections['plugin:catapult.plugins.metadata'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.metadata'].flds['maxFields'], '10'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.metadata'].flds['maxFieldKeySize'], '128'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.metadata'].flds['maxFieldValueSize'], '1024'),

                lambda x: ('plugin:catapult.plugins.mosaic' in x.network_config.sections, True),
                lambda x: ('maxMosaicsPerAccount' in x.network_config.sections['plugin:catapult.plugins.mosaic'].flds, True),
                lambda x: ('maxMosaicDuration' in x.network_config.sections['plugin:catapult.plugins.mosaic'].flds, True),
                lambda x: ('maxMosaicDivisibility' in x.network_config.sections['plugin:catapult.plugins.mosaic'].flds, True),
                lambda x: ('mosaicRentalFeeSinkPublicKey' in x.network_config.sections['plugin:catapult.plugins.mosaic'].flds, True),
                lambda x: ('mosaicRentalFee' in x.network_config.sections['plugin:catapult.plugins.mosaic'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.mosaic'].flds['maxMosaicsPerAccount'], '10\'000'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.mosaic'].flds['maxMosaicDuration'], '3650d'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.mosaic'].flds['maxMosaicDivisibility'], '6'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.mosaic'].flds['mosaicRentalFeeSinkPublicKey'], '94A9BB9660037E622C8F626E061DB1557CBBED0338402E82E796168E80EF9765'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.mosaic'].flds['mosaicRentalFee'], '10\'000\'000\'000'),

                lambda x: ('plugin:catapult.plugins.multisig' in x.network_config.sections, True),
                lambda x: ('maxMultisigDepth' in x.network_config.sections['plugin:catapult.plugins.multisig'].flds, True),
                lambda x: ('maxCosignersPerAccount' in x.network_config.sections['plugin:catapult.plugins.multisig'].flds, True),
                lambda x: ('maxCosignedAccountsPerAccount' in x.network_config.sections['plugin:catapult.plugins.multisig'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.multisig'].flds['maxMultisigDepth'], '3'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.multisig'].flds['maxCosignersPerAccount'], '10'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.multisig'].flds['maxCosignedAccountsPerAccount'], '1048576'),

                lambda x: ('plugin:catapult.plugins.namespace' in x.network_config.sections, True),
                lambda x: ('maxNameSize' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('maxNamespaceDuration' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('namespaceGracePeriodDuration' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('reservedRootNamespaceNames' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('namespaceRentalFeeSinkPublicKey' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('rootNamespaceRentalFeePerBlock' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('childNamespaceRentalFee' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: ('maxChildNamespaces' in x.network_config.sections['plugin:catapult.plugins.namespace'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['maxNameSize'], '64'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['maxNamespaceDuration'], '365d'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['namespaceGracePeriodDuration'], '0d'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['reservedRootNamespaceNames'], 'xem, nem, user, account, org, com, biz, net, edu, mil, gov, info, prx, xpx, xarcade, xar, proximax, prc, storage, so, sm, sc, rw'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['namespaceRentalFeeSinkPublicKey'], '9FF38184F03950C09FFFF4A90C171E4C3C566985EEACA486A59CC8B607C10BF6'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['rootNamespaceRentalFeePerBlock'], '4\'576'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['childNamespaceRentalFee'], '10\'000\'000\'000'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.namespace'].flds['maxChildNamespaces'], '500'),

                lambda x: ('plugin:catapult.plugins.property' in x.network_config.sections, True),
                lambda x: ('maxPropertyValues' in x.network_config.sections['plugin:catapult.plugins.property'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.property'].flds['maxPropertyValues'], '512'),

                lambda x: ('plugin:catapult.plugins.transfer' in x.network_config.sections, True),
                lambda x: ('maxMessageSize' in x.network_config.sections['plugin:catapult.plugins.transfer'].flds, True),
                lambda x: ('maxMosaicsSize' in x.network_config.sections['plugin:catapult.plugins.transfer'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.transfer'].flds['maxMessageSize'], '1024'),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.transfer'].flds['maxMosaicsSize'], '512'),

                lambda x: ('plugin:catapult.plugins.upgrade' in x.network_config.sections, True),
                lambda x: ('minUpgradePeriod' in x.network_config.sections['plugin:catapult.plugins.upgrade'].flds, True),
                lambda x: (x.network_config.sections['plugin:catapult.plugins.upgrade'].flds['minUpgradePeriod'], '360'),
                
                lambda x: (x.supported_entity_versions, '{\n    \"entities\": [\n        {\n            \"name\": \"Account_Link\",\n            \"type\": \"16716\",\n            \"supportedVersions\": [\n                2\n            ]\n        },\n        {\n            \"name\": \"Address_Metadata\",\n            \"type\": \"16701\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Address_Property\",\n            \"type\": \"16720\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Aggregate_Bonded\",\n            \"type\": \"16961\",\n            \"supportedVersions\": [\n                2\n            ]\n        },\n        {\n            \"name\": \"Aggregate_Complete\",\n            \"type\": \"16705\",\n            \"supportedVersions\": [\n                2\n            ]\n        },\n        {\n            \"name\": \"Alias_Address\",\n            \"type\": \"16974\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Alias_Mosaic\",\n            \"type\": \"17230\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Block\",\n            \"type\": \"33091\",\n            \"supportedVersions\": [\n                3\n            ]\n        },\n        {\n            \"name\": \"BlockChain_Upgrade\",\n            \"type\": \"16728\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Hash_Lock\",\n            \"type\": \"16712\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Modify_Contract\",\n            \"type\": \"16727\",\n            \"supportedVersions\": [\n                3\n            ]\n        },\n        {\n            \"name\": \"Modify_Multisig_Account\",\n            \"type\": \"16725\",\n            \"supportedVersions\": [\n                3\n            ]\n        },\n        {\n            \"name\": \"Mosaic_Definition\",\n            \"type\": \"16717\",\n            \"supportedVersions\": [\n                3\n            ]\n        },\n        {\n            \"name\": \"Mosaic_Metadata\",\n            \"type\": \"16957\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Mosaic_Property\",\n            \"type\": \"16976\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Mosaic_Supply_Change\",\n            \"type\": \"16973\",\n            \"supportedVersions\": [\n                2\n            ]\n        },\n        {\n            \"name\": \"Namespace_Metadata\",\n            \"type\": \"17213\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Nemesis_Block\",\n            \"type\": \"32835\",\n            \"supportedVersions\": [\n                3\n            ]\n        },\n        {\n            \"name\": \"Network_Config\",\n            \"type\": \"16729\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Register_Namespace\",\n            \"type\": \"16718\",\n            \"supportedVersions\": [\n                2\n            ]\n        },\n        {\n            \"name\": \"Secret_Lock\",\n            \"type\": \"16722\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Secret_Proof\",\n            \"type\": \"16978\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Transaction_Type_Property\",\n            \"type\": \"17232\",\n            \"supportedVersions\": [\n                1\n            ]\n        },\n        {\n            \"name\": \"Transfer\",\n            \"type\": \"16724\",\n            \"supportedVersions\": [\n                3\n            ]\n        }\n    ]\n}'),
            ],
        },
        {
            'name': 'test_get_and_serialize_config',
            'response': responses.CONFIG["Ok"],
            'params': [100],
            'method': 'get_config',
            'validation': [
                lambda x: (isinstance(x, models.CatapultConfig), True),
                lambda x: (isinstance(x.network_config, models.Sections), True),
                lambda x: (x.network_config.to_string(), '[network]\n\npublicKey = 5D3CE4904D04E9FDEB22D4273A960A8F954B9C60D622E2066DAC9B3EA8A943CB\n\n[chain]\n\nblockGenerationTargetTime = 15s\nblockTimeSmoothingFactor = 3000\ngreedDelta = 0.5\ngreedExponent = 3.2\nimportanceGrouping = 5760\nmaxRollbackBlocks = 360\nmaxDifficultyBlocks = 4\nmaxTransactionLifetime = 24h\nmaxBlockFutureTime = 10s\nmaxMosaicAtomicUnits = 9\'000\'000\'000\'000\'001\ntotalChainImportance = 9\'000\'000\'000\'000\'000\nminHarvesterBalance = 100\'000\'000\'000\nharvestBeneficiaryPercentage = 10\nblockPruneInterval = 360\nmaxTransactionsPerBlock = 200\'000\nenableUnconfirmedTransactionMinFeeValidation = false\n\n[plugin:catapult.plugins.accountlink]\n\ndummy = to trigger plugin load\n\n[plugin:catapult.plugins.aggregate]\n\nmaxTransactionsPerAggregate = 1\'000\nmaxCosignaturesPerAggregate = 15\nenableStrictCosignatureCheck = false\nenableBondedAggregateSupport = true\nmaxBondedTransactionLifetime = 48h\n\n[plugin:catapult.plugins.config]\n\nmaxBlockChainConfigSize = 1MB\nmaxSupportedEntityVersionsSize = 1MB\n\n[plugin:catapult.plugins.contract]\n\nminPercentageOfApproval = 100\nminPercentageOfRemoval = 66\n\n[plugin:catapult.plugins.lockhash]\n\nlockedFundsPerAggregate = 10\'000\'000\nmaxHashLockDuration = 2d\n\n[plugin:catapult.plugins.locksecret]\n\nmaxSecretLockDuration = 30d\nminProofSize = 1\nmaxProofSize = 1000\n\n[plugin:catapult.plugins.metadata]\n\nmaxFields = 10\nmaxFieldKeySize = 128\nmaxFieldValueSize = 1024\n\n[plugin:catapult.plugins.mosaic]\n\nmaxMosaicsPerAccount = 10\'000\nmaxMosaicDuration = 3650d\nmaxMosaicDivisibility = 6\nmosaicRentalFeeSinkPublicKey = 94A9BB9660037E622C8F626E061DB1557CBBED0338402E82E796168E80EF9765\nmosaicRentalFee = 10\'000\'000\'000\n\n[plugin:catapult.plugins.multisig]\n\nmaxMultisigDepth = 3\nmaxCosignersPerAccount = 10\nmaxCosignedAccountsPerAccount = 1048576\n\n[plugin:catapult.plugins.namespace]\n\nmaxNameSize = 64\nmaxNamespaceDuration = 365d\nnamespaceGracePeriodDuration = 0d\nreservedRootNamespaceNames = xem, nem, user, account, org, com, biz, net, edu, mil, gov, info, prx, xpx, xarcade, xar, proximax, prc, storage, so, sm, sc, rw\nnamespaceRentalFeeSinkPublicKey = 9FF38184F03950C09FFFF4A90C171E4C3C566985EEACA486A59CC8B607C10BF6\nrootNamespaceRentalFeePerBlock = 4\'576\nchildNamespaceRentalFee = 10\'000\'000\'000\nmaxChildNamespaces = 500\n\n[plugin:catapult.plugins.property]\n\nmaxPropertyValues = 512\n\n[plugin:catapult.plugins.transfer]\n\nmaxMessageSize = 1024\nmaxMosaicsSize = 512\n\n[plugin:catapult.plugins.upgrade]\n\nminUpgradePeriod = 360\n\n'),
            ],
        },
        {
            'name': 'test_get_upgrade',
            'response': responses.UPGRADE["Ok"],
            'params': [100],
            'method': 'get_upgrade',
            'validation': [
                lambda x: (isinstance(x, models.CatapultUpgrade), True),
                lambda x: (isinstance(x.blockchain_upgrade, models.Upgrade), True),
                lambda x: (x.blockchain_upgrade.height, 1),
                lambda x: (x.blockchain_upgrade.blockchain_version, 17180000256),
            ],
        },
    ],
})
class TestConfigHTTP(harness.TestCase):
    pass
