├── .eslintignore ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .gitmodules ├── .solcover.js ├── .soliumignore ├── .soliumrc.json ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SOLIDITY_STYLE_GUIDE.md ├── VERSION.md ├── contracts ├── anchor │ └── Anchor.sol ├── core │ ├── AuxiliaryBlockStore.sol │ ├── AuxiliaryTransitionObjectInterface.sol │ ├── BlockStore.sol │ ├── BlockStoreInterface.sol │ ├── InitializeGatewayKernelInterface.sol │ ├── KernelGateway.sol │ ├── KernelGatewayInterface.sol │ ├── MosaicCore.sol │ ├── MosaicCoreConfig.sol │ ├── MosaicCoreInterface.sol │ ├── OriginTransitionObjectInterface.sol │ ├── PollingPlace.sol │ ├── PollingPlaceInterface.sol │ ├── Stake.sol │ └── StakeInterface.sol ├── gateway │ ├── EIP20CoGateway.sol │ ├── EIP20CoGatewayInterface.sol │ ├── EIP20Gateway.sol │ ├── EIP20GatewayInterface.sol │ ├── EIP20Token.sol │ ├── GatewayBase.sol │ ├── GatewayRedeemInterface.sol │ ├── OSTComposer.sol │ ├── OSTPrime.sol │ ├── OSTPrimeConfig.sol │ ├── RedeemPool.sol │ ├── RedeemerProxy.sol │ ├── SimpleStake.sol │ └── StakerProxy.sol ├── lib │ ├── Block.sol │ ├── BytesLib.sol │ ├── CircularBufferUint.sol │ ├── EIP20Interface.sol │ ├── GatewayLib.sol │ ├── MerklePatriciaProof.sol │ ├── MerklePatriciaProofTest.sol │ ├── MessageBus.sol │ ├── MetaBlock.sol │ ├── Mutex.sol │ ├── OstInterface.sol │ ├── RLP.sol │ ├── RLPEncode.sol │ └── StateRootInterface.sol ├── test │ ├── EIP20StandardToken.sol │ ├── anchor │ │ └── MockAnchor.sol │ ├── core │ │ ├── MockBlockStore.sol │ │ ├── MockPollingPlace.sol │ │ ├── TestKernelGateway.sol │ │ ├── TestKernelGatewayFail.sol │ │ └── TestMosaicCore.sol │ ├── gateway │ │ ├── MockEIP20CoGateway.sol │ │ ├── MockEIP20Token.sol │ │ ├── MockGatewayBase.sol │ │ ├── MockRedeemerProxy.sol │ │ ├── MockStakerProxy.sol │ │ ├── MockToken.sol │ │ ├── MockTokenConfig.sol │ │ ├── MockUtilityToken.sol │ │ ├── SpyEIP20CoGateway.sol │ │ ├── SpyEIP20Gateway.sol │ │ ├── SpyToken.sol │ │ ├── TestEIP20CoGateway.sol │ │ ├── TestEIP20Gateway.sol │ │ ├── TestGatewayBase.sol │ │ ├── TestOSTComposer.sol │ │ └── TestOSTPrime.sol │ ├── lib │ │ ├── MockGatewayLib.sol │ │ ├── MockMerklePatriciaProof.sol │ │ ├── MockMessageBus.sol │ │ ├── TestCircularBufferUint.sol │ │ └── TestRLP.sol │ └── test_lib │ │ ├── KeyValueStoreStub.sol │ │ ├── MessageBusWrapper.sol │ │ └── RevertProxy.sol └── truffle │ └── Migrations.sol ├── docs ├── OpenSTwp.pdf ├── diagrams │ ├── v092 │ │ └── stakemintv092.png │ └── v093 │ │ └── stakemint │ │ ├── stakemintv093.pdf │ │ └── stakemintv093.tex ├── mosaicv0.pdf └── protocol.png ├── index.ts ├── migrations ├── 1_initial_migration.js └── 2_deploy_contracts.js ├── package-lock.json ├── package.json ├── proof_generation ├── deployer.js ├── docker.js ├── generator.js ├── helper │ ├── co_gateway.js │ └── gateway.js ├── main.sh └── proof_generation_utils.js ├── test ├── anchor │ └── anchor │ │ ├── anchor_state_root.js │ │ ├── constructor.js │ │ ├── get_latest_state_root_block_height.js │ │ ├── get_remote_chainId.js │ │ ├── get_state_root.js │ │ └── set_co_anchor_address.js ├── core │ ├── auxiliary_block_store │ │ ├── auxiliary_transition_hash_at_block.js │ │ ├── auxiliary_transition_object_at_block.js │ │ ├── constructor.js │ │ ├── helpers │ │ │ ├── aux_store_utils.js │ │ │ └── data.js │ │ ├── initialize_kernel_gateway.js │ │ ├── is_vote_valid.js │ │ ├── justify.js │ │ ├── latest_block_height.js │ │ ├── report_block.js │ │ └── state_root.js │ ├── block_store │ │ ├── constructor.js │ │ ├── is_vote_valid.js │ │ ├── justify.js │ │ ├── latest_block_height.js │ │ ├── report_block.js │ │ ├── state_root.js │ │ ├── transition_hash_at_block.js │ │ └── transition_object_at_block.js │ ├── kernel_gateway │ │ ├── activate_kernel.js │ │ ├── constructor.js │ │ ├── get_active_kernel_hash.js │ │ ├── get_open_kernel.js │ │ ├── get_open_kernel_hash.js │ │ ├── get_updated_validators.js │ │ ├── prove_block_opening.js │ │ └── prove_origin_core.js │ ├── mosaic_core │ │ ├── constructor.js │ │ ├── get_accumulated_gas_target.js │ │ ├── get_latest_state_root_block_height.js │ │ ├── get_storage_root.js │ │ ├── helpers │ │ │ └── utils.js │ │ ├── propose_block.js │ │ └── verify_vote.js │ ├── polling_place │ │ ├── constructor.js │ │ ├── update_meta_block.js │ │ └── vote.js │ └── stake │ │ ├── TestStake.sol │ │ ├── close_meta_block.js │ │ ├── constructor.js │ │ ├── deposit.js │ │ ├── helpers │ │ └── stake_utils.js │ │ ├── initialize.js │ │ ├── total_weight_at_height.js │ │ └── weight.js ├── data │ ├── generatedProofData.json │ ├── proof.json │ ├── redeem_progressed_0.json │ ├── redeem_progressed_1.json │ ├── redeem_progressed_reward_based_on_gas_consumption.json │ ├── redeem_revoked_0.json │ ├── redeem_revoked_1.json │ ├── stake_progressed_0.json │ ├── stake_progressed_1.json │ ├── stake_revoked_0.json │ └── stake_revoked_1.json ├── gateway │ ├── EIP20_token_utils.js │ ├── eip20_cogateway │ │ ├── confirm_revert_stake_intent.js │ │ ├── confirm_stake_intent.js │ │ ├── constructor.js │ │ ├── helpers │ │ │ └── co_gateway_utils.js │ │ ├── penalty.js │ │ ├── progress_mint.js │ │ ├── progress_mint_with_proof.js │ │ ├── progress_redeem.js │ │ ├── progress_redeem_with_proof.js │ │ ├── progress_revert_redeem.js │ │ ├── redeem.js │ │ └── revert_redeem.js │ ├── eip20_gateway │ │ ├── activate_gateway.js │ │ ├── confirm_redeem_intent.js │ │ ├── confirm_revert_redeem_intent.js │ │ ├── constructor.js │ │ ├── deactivate_gateway.js │ │ ├── helpers │ │ │ └── gateway_utils.js │ │ ├── penalty.js │ │ ├── progress_revert_stake.js │ │ ├── progress_stake.js │ │ ├── progress_stake_with_proof.js │ │ ├── progress_unstake.js │ │ ├── progress_unstake_with_proof.js │ │ ├── revert_stake.js │ │ └── stake.js │ ├── gateway_base │ │ ├── bounty_change.js │ │ ├── construction.js │ │ ├── get_inbox_active_process.js │ │ ├── get_inbox_message_status.js │ │ ├── get_nonce.js │ │ ├── get_outbox_active_process.js │ │ ├── get_outbox_message_status.js │ │ └── prove_gateway.js │ ├── message_bus │ │ ├── declare_revocation_message.js │ │ ├── progress_inbox.js │ │ └── verify_signature.js │ ├── mock_token.js │ ├── mock_token_utils.js │ ├── ost_composer │ │ ├── accept_stake.js │ │ ├── constructor.js │ │ ├── destruct_staker_proxy.js │ │ ├── helpers │ │ │ └── composer_utils.js │ │ ├── reject_stake_request.js │ │ ├── request_stake.js │ │ └── revoke_stake_request.js │ ├── ost_prime │ │ ├── constructor.js │ │ ├── decrease_supply.js │ │ ├── increase_supply.js │ │ ├── initialize.js │ │ ├── unwrap.js │ │ └── wrap.js │ ├── redeem_pool │ │ ├── accept_redeem_request.js │ │ ├── destruct_redeemer_proxy.js │ │ ├── reject_redeem_request.js │ │ ├── request_redeem.js │ │ └── revoke_redeem_request.js │ ├── redeem_proxy │ │ ├── constructor.js │ │ ├── redeem.js │ │ ├── self_destruct.js │ │ └── transfer_token.js │ ├── simple_stake │ │ ├── constructor.js │ │ ├── get_total_stake.js │ │ └── release_to.js │ └── staker_proxy │ │ ├── constructor.js │ │ ├── self_destruct.js │ │ ├── stake.js │ │ └── transfer_token.js ├── lib │ ├── RLP.js │ ├── TestBlock.sol │ ├── TestMessageBus.sol │ ├── TestMetaBlock.sol │ ├── circular_buffer_uint │ │ ├── constructor.js │ │ └── store.js │ ├── gatewaylib │ │ ├── hash_redeem_intent.js │ │ ├── hash_stake_intent.js │ │ └── prove_account.js │ ├── merkle_patricia_proof.js │ ├── messagebus │ │ ├── confirm_message.js │ │ ├── confirm_revocation.js │ │ ├── declare_message.js │ │ ├── declare_revocation_message.js │ │ ├── messagebus_utils.js │ │ ├── progress_inbox.js │ │ ├── progress_inbox_with_proof.js │ │ ├── progress_outbox.js │ │ ├── progress_outbox_revocation.js │ │ └── progress_outbox_with_proof.js │ ├── organization │ │ ├── complete_ownership_transfer.js │ │ ├── constructor.js │ │ ├── initiate_ownership_transfer.js │ │ ├── is_organization.js │ │ ├── is_worker.js │ │ ├── set_admin.js │ │ ├── set_worker.js │ │ └── unset_worker.js │ ├── organized │ │ └── constructor.js │ └── safe_math.js └── test_lib │ ├── config.js │ ├── event_decoder.js │ ├── hash_lock.js │ ├── message_bus.js │ ├── meta_block.js │ ├── utils.js │ └── web3.js ├── test_integration ├── 01_deployment │ └── 01_deploy.js ├── 02_stake_and_mint │ ├── 01_stake_and_mint.js │ ├── 02_stake_and_mint_proof.js │ ├── 03_revert_stake_and_mint.js │ ├── 04_stake_and_mint_after_revert.js │ └── utils │ │ ├── confirm_revert_stake_intent_assertion.js │ │ ├── confirm_stake_intent_assertion.js │ │ ├── progress_mint_assertion.js │ │ ├── progress_revert_stake_assertion.js │ │ ├── progress_stake_assertion.js │ │ ├── revert_stake_assertion.js │ │ └── stake_assertion.js ├── 03_redeem_and_unstake │ ├── 01_redeem_and_unstake.js │ ├── 02_redeem_and_unstake_with_redeem_composer.js │ ├── 03_redeem_and_unstake_proof.js │ ├── 04_revert_redeem.js │ ├── 05_redeem_and_unstake_after_revert.js │ └── utils │ │ ├── accept_redeem_assertion.js │ │ ├── confirm_redeem_intent_assertion.js │ │ ├── confirm_revert_redeem_intent_assertion.js │ │ ├── progress_redeem_assertion.js │ │ ├── progress_revert_redeem_assertion.js │ │ ├── progress_unstake_assertion.js │ │ ├── redeem_assertion.js │ │ ├── request_redeem_assertion.js │ │ └── revert_redeem_assertion.js ├── docker-compose.yml ├── docker.js ├── integration_tests.js ├── lib │ ├── anchor.js │ ├── anchor_stateroot_assertion.js │ ├── proof_utils.js │ └── prove_gateway_assertion.js ├── main.sh └── shared.js ├── tools ├── README.md ├── blue_deployment │ ├── cli │ │ ├── checks.js │ │ └── prompts.js │ ├── contracts.js │ ├── index.js │ └── scripts │ │ └── step1_origin_contracts.js ├── build_package.js ├── contract_interact_generator.js ├── deployment_tool │ ├── Contract.js │ ├── ContractRegistry.js │ ├── address_generators.js │ ├── index.js │ ├── test │ │ └── deployment_tools.test.js │ └── utils.js ├── fuzzy_proof_generator_tool │ ├── generate.ts │ ├── patterns.ts │ ├── src │ │ ├── BranchNode.ts │ │ ├── ExtensionNode.ts │ │ ├── FuzzyProofGenerator.ts │ │ ├── LeafNode.ts │ │ ├── Nibbles.ts │ │ ├── NodeBase.ts │ │ ├── ProofData.ts │ │ └── Types.ts │ └── test │ │ ├── ExtensionNode │ │ └── encodeCompact.test.ts │ │ ├── FuzzyProofGenerator │ │ ├── assertPatternValidity.test.ts │ │ ├── generate.js │ │ └── generateByPattern.js │ │ ├── LeafNode │ │ └── encodeCompact.test.ts │ │ ├── Nibbles │ │ ├── assertNibbleArray.test.ts │ │ ├── nibblesToBuffer.test.ts │ │ └── toNibbles.test.ts │ │ └── run.sh ├── merge_chainspec_accounts.js ├── runGanacheCli.sh ├── test_range.sh └── tools_tsconfig.json ├── truffle.js ├── ts-generator.json └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | tools/fuzzy_proof_generator_tool/src/*.js 3 | tools/fuzzy_proof_generator_tool/src/*.js.map 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb-base", 4 | "plugin:@typescript-eslint/recommended" 5 | ], 6 | "parser": "@typescript-eslint/parser", 7 | "parserOptions": { 8 | "project": "./tsconfig.json", 9 | "sourceType": "module", 10 | "ecmaFeatures": { 11 | "modules": true 12 | } 13 | }, 14 | "plugins": [ 15 | "@typescript-eslint", 16 | "json" 17 | ], 18 | "rules": { 19 | "@typescript-eslint/camelcase": "off", 20 | "@typescript-eslint/indent": ["error", 2], 21 | "@typescript-eslint/await-thenable": "error", 22 | "@typescript-eslint/no-for-in-array": "error", 23 | "@typescript-eslint/no-unnecessary-qualifier": "error", 24 | "@typescript-eslint/no-unnecessary-type-assertion": "error", 25 | "@typescript-eslint/no-extraneous-class": "error", 26 | "@typescript-eslint/prefer-includes": "error", 27 | "@typescript-eslint/restrict-plus-operands": "error", 28 | "@typescript-eslint/no-useless-constructor": "error", 29 | "@typescript-eslint/unified-signatures": "error", 30 | "@typescript-eslint/unbound-method": [ 31 | "error", 32 | { 33 | "ignoreStatic": true 34 | } 35 | ], 36 | "@typescript-eslint/promise-function-async": [ 37 | "error", 38 | { 39 | "checkArrowFunctions": true, 40 | "checkFunctionDeclarations": true, 41 | "checkFunctionExpressions": true, 42 | "checkMethodDeclarations": true 43 | } 44 | ], 45 | "no-console": "off", 46 | "no-underscore-dangle": "off", 47 | "import/no-extraneous-dependencies": "off", 48 | "strict": "off" 49 | }, 50 | "env": { 51 | "mocha": true, 52 | "node": true, 53 | "es6": true 54 | }, 55 | "globals": { 56 | "artifacts": false, 57 | "contract": false, 58 | "assert": false 59 | }, 60 | "settings": { 61 | "import/resolver": { 62 | "node": { 63 | "extensions": [".js", ".jsx", ".ts", ".tsx"] 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | .DS_Store 3 | 4 | # Vagrant 5 | .vagrant/ 6 | ubuntu-xenial-16.04-cloudimg-console.log 7 | 8 | # don't commit contract binaries in protocol 9 | # we do commit the contract binaries in platform 10 | contracts/bin/ 11 | contracts/abi/ 12 | 13 | # don't commit node_modules 14 | node_modules 15 | 16 | # Do not track builds 17 | build/ 18 | 19 | # Do not track IDE files 20 | .idea/ 21 | .vscode/ 22 | *.iml 23 | *.swp 24 | tags 25 | 26 | # LaTeX auxiliary files 27 | *.aux 28 | *.log 29 | 30 | # NPM package generated files: 31 | dist 32 | contract_build 33 | 34 | 35 | ## Build tool auxiliary files: 36 | *.synctex 37 | *.synctex(busy) 38 | *.synctex.gz 39 | *.synctex.gz(busy) 40 | *.pdfsync 41 | 42 | # Compiled js artifacts. 43 | tools/fuzzy_proof_generator_tool/src/*.js 44 | tools/fuzzy_proof_generator_tool/src/*.js.map 45 | 46 | # Do not track generated wrapper, it should be part of build script 47 | interacts/* 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "contracts/utilitytoken"] 2 | path = contracts/utilitytoken 3 | url = https://github.com/OpenST/utilitytoken-contracts.git 4 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | port: 8555, 3 | testrpcOptions: '--port 8555 --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea0,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea1,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea2,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea3,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea4,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea5,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea6,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea7,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea8,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea9,0" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb0,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb1,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb2,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb3,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb4,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb5,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb6,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb7,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb8,10000000000000000000000000000000000" --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb9,0"', 4 | skipFiles: ['gateway/MockAnchor.sol','gateway/EIP20TokenMock.sol','gateway/OpenSTUtilityMock.sol','gateway/OpenSTValueMock.sol','gateway/ProtocolVersionedMock.sol','gateway/SafeMathMock.sol','gateway/UtilityTokenAbstractMock.sol','truffle/Migrations.sol'] 5 | }; -------------------------------------------------------------------------------- /.soliumignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | contracts/truffle/Migrations.sol 3 | -------------------------------------------------------------------------------- /.soliumrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solium:recommended", 3 | "plugins": [ 4 | "security" 5 | ], 6 | "rules": { 7 | "quotes": [ 8 | "error", 9 | "double" 10 | ], 11 | "indentation": [ 12 | "error", 13 | 4 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: node_js 3 | cache: npm 4 | sudo: required 5 | env: 6 | - TEST_SUITE="test:deployment_tool", 7 | - TEST_SUITE="test:fuzzy_proof_generator", 8 | - TEST_SUITE="test:integration", 9 | - TEST_SUITE="test:unit", 10 | - TEST_SUITE="build:package" 11 | branches: 12 | only: 13 | - master 14 | - develop 15 | - /^feature\/.*/ 16 | - /^release-.*/ 17 | - /^hotfix-.*/ 18 | notifications: 19 | email: 20 | recipients: 21 | - ci.report@ost.com 22 | on_success: always 23 | on_failure: always 24 | node_js: 25 | - "8" 26 | before_script: 27 | - npm run compile 28 | - npm run build:package 29 | - npm run generate:interacts 30 | - npm run compile:ts 31 | - ./tools/runGanacheCli.sh /dev/null 2>&1 & 32 | script: 33 | - npm run ${TEST_SUITE} 34 | after_script: 35 | - kill $(ps aux | grep 'ganache-cli' | awk '{print $2}') 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 OpenST 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /VERSION.md: -------------------------------------------------------------------------------- 1 | 0.9.1 2 | -------------------------------------------------------------------------------- /contracts/core/InitializeGatewayKernelInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "./KernelGatewayInterface.sol"; 24 | 25 | /** @title The interface for opening the new kernel on auxiliary. */ 26 | interface InitializeGatewayKernelInterface { 27 | 28 | /** 29 | * @notice Set kernel gateway 30 | * 31 | * @param _kernelGateway The kernel gateway address 32 | */ 33 | function initialize(KernelGatewayInterface _kernelGateway) 34 | external; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /contracts/core/MosaicCoreConfig.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** @title Configuration constants of the MosaicCore contract. */ 24 | contract MosaicCoreConfig { 25 | 26 | /** The number of decimals of the base token. */ 27 | uint256 public constant DECIMALSFACTOR = 10 ** uint256(18); 28 | 29 | /** The cost in base tokens that it costs a validator to report a block. */ 30 | uint256 public constant COST_REPORT_BLOCK = 1 * DECIMALSFACTOR; 31 | } 32 | -------------------------------------------------------------------------------- /contracts/core/OriginTransitionObjectInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** @title The interface for the transition object on origin. */ 24 | interface OriginTransitionObjectInterface { 25 | 26 | /** 27 | * @notice Returns transition hash at the checkpoint defined at the given 28 | * block hash. 29 | * 30 | * @param _blockHash The hash of the block for which transition object 31 | * is requested. 32 | * 33 | * @return transitionHash_ Hash of the transition object at the checkpoint. 34 | */ 35 | function transitionHashAtBlock( 36 | bytes32 _blockHash 37 | ) 38 | external 39 | view 40 | returns(bytes32 transitionHash_); 41 | 42 | /** 43 | * @notice Returns transition object at the checkpoint defined at given 44 | * block hash. 45 | * 46 | * @param _blockHash The hash of the block for which transition object 47 | * is requested. 48 | * 49 | * @return coreIdentifier_ The core identifier identifies the chain that 50 | * this block store is tracking. 51 | * @return dynasty_ Dynasty number of checkpoint for which transition 52 | * object is requested. 53 | * @return blockHash_ Hash of the block at checkpoint. 54 | */ 55 | function transitionObjectAtBlock( 56 | bytes32 _blockHash 57 | ) 58 | external 59 | view 60 | returns( 61 | bytes20 coreIdentifier_, 62 | uint256 dynasty_, 63 | bytes32 blockHash_ 64 | ); 65 | } 66 | -------------------------------------------------------------------------------- /contracts/gateway/EIP20CoGatewayInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../lib/EIP20Interface.sol"; 24 | 25 | 26 | interface EIP20CoGatewayInterface { 27 | 28 | /** 29 | * @notice Initiates the redeem process. 30 | * 31 | * @dev In order to redeem the redeemer needs to approve CoGateway contract 32 | * for redeem amount. Redeem amount is transferred from redeemer 33 | * address to CoGateway contract. 34 | * This is a payable function. The bounty is transferred in base coin. 35 | * Redeemer is always msg.sender. 36 | * 37 | * @param _amount Redeem amount that will be transferred from redeemer 38 | * account. 39 | * @param _beneficiary The address in the origin chain where the value 40 | * tok ens will be released. 41 | * @param _gasPrice Gas price that redeemer is ready to pay to get the 42 | * redeem process done. 43 | * @param _gasLimit Gas limit that redeemer is ready to pay. 44 | * @param _nonce Nonce of the redeemer address. 45 | * @param _hashLock Hash Lock provided by the facilitator. 46 | * 47 | * @return messageHash_ Unique for each request. 48 | */ 49 | function redeem( 50 | uint256 _amount, 51 | address _beneficiary, 52 | uint256 _gasPrice, 53 | uint256 _gasLimit, 54 | uint256 _nonce, 55 | bytes32 _hashLock 56 | ) 57 | external 58 | payable 59 | returns (bytes32 messageHash_); 60 | 61 | /** 62 | * @notice Get the nonce for the given account address. 63 | * 64 | * @param _account Account address for which the nonce is to be fetched. 65 | * 66 | * @return The nonce. 67 | */ 68 | function getNonce(address _account) 69 | external 70 | view 71 | returns (uint256); 72 | 73 | /** 74 | * @notice Amount of EIP20 which is staked by facilitator. 75 | * 76 | * @return The amount. 77 | */ 78 | function bounty() external view returns (uint256); 79 | 80 | /** 81 | * @notice Get the utilityToken token of this cogateway. 82 | * 83 | * @return The address of the utilitytoken. 84 | */ 85 | function utilityToken() external view returns (EIP20Interface); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /contracts/gateway/EIP20GatewayInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../lib/EIP20Interface.sol"; 24 | 25 | 26 | interface EIP20GatewayInterface { 27 | 28 | /** 29 | * @notice Initiates the stake process. In order to stake the staker 30 | * needs to approve Gateway contract for stake amount. 31 | * Staked amount is transferred from staker address to 32 | * Gateway contract. Bounty amount is also transferred from staker. 33 | * 34 | * @param _amount Stake amount that will be transferred from the staker 35 | * account. 36 | * @param _beneficiary The address in the auxiliary chain where the utility 37 | * tokens will be minted. 38 | * @param _gasPrice Gas price that staker is ready to pay to get the stake 39 | * and mint process done. 40 | * @param _gasLimit Gas limit that staker is ready to pay. 41 | * @param _nonce Nonce of the staker address. 42 | * @param _hashLock Hash Lock provided by the facilitator. 43 | * 44 | * @return messageHash_ Message hash is unique for each request. 45 | */ 46 | function stake( 47 | uint256 _amount, 48 | address _beneficiary, 49 | uint256 _gasPrice, 50 | uint256 _gasLimit, 51 | uint256 _nonce, 52 | bytes32 _hashLock 53 | ) 54 | external 55 | returns (bytes32 messageHash_); 56 | 57 | /** 58 | * @notice Get the nonce for the given account address. 59 | * 60 | * @param _account Account address for which the nonce is to be fetched. 61 | * 62 | * @return The nonce. 63 | */ 64 | function getNonce(address _account) 65 | external 66 | view 67 | returns (uint256); 68 | 69 | /** 70 | * @notice Amount of EIP20 which is staked by facilitator. 71 | * 72 | * @return The amount. 73 | */ 74 | function bounty() external view returns (uint256); 75 | 76 | /** 77 | * @notice Get the value token of this gateway. 78 | * 79 | * @return The address of the value token. 80 | */ 81 | function token() external view returns (EIP20Interface); 82 | 83 | /** 84 | * @notice Get the base token of this gateway. 85 | * 86 | * @return The address of the base token. 87 | */ 88 | function baseToken() external view returns (EIP20Interface); 89 | } 90 | -------------------------------------------------------------------------------- /contracts/gateway/OSTPrimeConfig.sol: -------------------------------------------------------------------------------- 1 | /* solhint-disable-next-line compiler-fixed */ 2 | pragma solidity ^0.5.0; 3 | 4 | // Copyright 2019 OpenST Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | // ---------------------------------------------------------------------------- 19 | // Utility chain: OSTPrimeConfig 20 | // 21 | // http://www.simpletoken.org/ 22 | // 23 | // ---------------------------------------------------------------------------- 24 | 25 | /* solhint-disable-next-line two-lines-top-level-separator */ 26 | /** 27 | * @title OSTPrimeConfig contract. 28 | * 29 | * @notice Contains configuration constants utilized by the OSTPrime contract. 30 | */ 31 | contract OSTPrimeConfig { 32 | 33 | /** Constants */ 34 | 35 | string public constant TOKEN_SYMBOL = "ST"; 36 | string public constant TOKEN_NAME = "Simple Token"; 37 | uint8 public constant TOKEN_DECIMALS = 18; 38 | 39 | /** Storage */ 40 | 41 | uint256 public constant DECIMALSFACTOR = 10**uint256(TOKEN_DECIMALS); 42 | uint256 public constant TOKENS_MAX = 800000000 * DECIMALSFACTOR; 43 | } 44 | -------------------------------------------------------------------------------- /contracts/lib/Block.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "./RLP.sol"; 24 | 25 | /** 26 | * @title Block provides functionality to work with blocks. 27 | */ 28 | library Block { 29 | 30 | /* Structs */ 31 | 32 | struct Header { 33 | bytes32 blockHash; 34 | bytes32 parentHash; 35 | bytes32 uncleHash; 36 | address coinbase; 37 | bytes32 stateRoot; 38 | bytes32 transactionRoot; 39 | bytes32 receiptRoot; 40 | bytes logsBloom; 41 | uint256 difficulty; 42 | uint256 height; 43 | uint64 gasLimit; 44 | uint64 gasUsed; 45 | uint256 timeStamp; 46 | bytes extraData; 47 | bytes32 mixDigest; 48 | uint256 nonce; 49 | } 50 | 51 | /* Internal Functions */ 52 | 53 | /** 54 | * @notice Decodes an RLP-encoded header into a Header struct. 55 | * 56 | * @param _blockHeaderRlp An RLP-encoded block header. 57 | * 58 | * @return header_ The header struct with the data decoded from the input. 59 | */ 60 | function decodeHeader( 61 | bytes memory _blockHeaderRlp 62 | ) 63 | internal 64 | pure 65 | returns (Header memory header_) 66 | { 67 | bytes32 blockHash = keccak256(_blockHeaderRlp); 68 | 69 | RLP.RLPItem memory header = RLP.toRLPItem(_blockHeaderRlp); 70 | RLP.RLPItem[] memory headerFields = RLP.toList(header); 71 | 72 | header_ = Header( 73 | blockHash, 74 | RLP.toBytes32(headerFields[0]), 75 | RLP.toBytes32(headerFields[1]), 76 | RLP.toAddress(headerFields[2]), 77 | RLP.toBytes32(headerFields[3]), 78 | RLP.toBytes32(headerFields[4]), 79 | RLP.toBytes32(headerFields[5]), 80 | RLP.toBytes(headerFields[6]), 81 | uint256(RLP.toUint(headerFields[7])), 82 | uint256(RLP.toUint(headerFields[8])), 83 | uint64(RLP.toUint(headerFields[9])), 84 | uint64(RLP.toUint(headerFields[10])), 85 | uint256(RLP.toUint(headerFields[11])), 86 | RLP.toBytes(headerFields[12]), 87 | RLP.toBytes32(headerFields[13]), 88 | uint256(RLP.toUint(headerFields[14])) 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /contracts/lib/MerklePatriciaProofTest.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./MerklePatriciaProof.sol"; 4 | 5 | /** 6 | * @title This contract is a test contract for testing MerklePatriciaProof library contract 7 | * 8 | * @notice It routes the parameters to MerklePatriciaProof.sol which it receives from test cases 9 | * 10 | */ 11 | contract MerklePatriciaProofTest { 12 | 13 | 14 | /** 15 | * @notice This method is used for Account proof 16 | * 17 | * @param value The terminating value in the trie 18 | * @param encodedPath The path in the trie leading to value 19 | * @param rlpParentNodes The rlp encoded stack of nodes 20 | * @param root The root hash of the trie 21 | * 22 | * @return The boolean validity of the proof 23 | */ 24 | function verifyAccount( 25 | bytes32 value, 26 | bytes calldata encodedPath, 27 | bytes calldata rlpParentNodes, 28 | bytes32 root) 29 | external 30 | pure 31 | returns (bool) 32 | { 33 | return MerklePatriciaProof.verify(value,encodedPath,rlpParentNodes,root); 34 | } 35 | 36 | /** 37 | * @notice This method is used for Storage proof 38 | * 39 | * @param value The terminating value in the trie 40 | * @param encodedPath The path in the trie leading to value 41 | * @param rlpParentNodes The rlp encoded stack of nodes 42 | * @param root The root hash of the trie 43 | * 44 | * @return The boolean validity of the proof 45 | */ 46 | function verifyStorage( 47 | bytes32 value, 48 | bytes calldata encodedPath, 49 | bytes calldata rlpParentNodes, 50 | bytes32 root) 51 | external 52 | pure 53 | returns (bool) 54 | { 55 | return MerklePatriciaProof.verify(value,encodedPath,rlpParentNodes,root); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /contracts/lib/Mutex.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** @title Mutex contract provide locking mechanism. */ 24 | contract Mutex { 25 | 26 | /* Storage */ 27 | 28 | bool private mutexAcquired; 29 | 30 | 31 | /* Modifiers */ 32 | 33 | /** 34 | * Checks that mutex is acquired or not. If mutex is not acquired, 35 | * mutexAcquired is set to true. At the end of function execution, 36 | * mutexAcquired is set to false. 37 | */ 38 | modifier mutex() { 39 | require( 40 | !mutexAcquired, 41 | "Mutex is already acquired." 42 | ); 43 | mutexAcquired = true; 44 | _; 45 | mutexAcquired = false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /contracts/lib/OstInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** @title An interface to an OST ERC-20 token. */ 24 | interface OstInterface { 25 | 26 | /** 27 | * @return The number of decimals that this ERC-20 token has. 28 | */ 29 | function decimals() 30 | external 31 | view 32 | returns (uint8); 33 | 34 | /** 35 | * @notice Transfers the given amount of tokens to the given recipient. 36 | * 37 | * @param _to The recipient of the tokens. 38 | * @param _value The amount of tokens to transfer. 39 | * 40 | * @return success Indicates whether the transfer was successful. 41 | */ 42 | function transfer( 43 | address _to, 44 | uint256 _value 45 | ) 46 | external 47 | returns (bool success); 48 | 49 | /** 50 | * @notice Transfers the given amount of tokens from the given sender to 51 | * the given recipient. 52 | * 53 | * @param _from The sender of the tokens. 54 | * @param _to The recipient of the tokens. 55 | * @param _value The amount of tokens to transfer. 56 | * 57 | * @return success Indicates whether the transfer was successful. 58 | */ 59 | function transferFrom( 60 | address _from, 61 | address _to, 62 | uint256 _value 63 | ) 64 | external 65 | returns (bool success); 66 | 67 | /** 68 | * @notice Burns the given amount of tokens and removes them from the total 69 | * supply. 70 | * 71 | * @param _value The amount of tokens to burn. 72 | * 73 | * @return success Indicates whether the burn was successful. 74 | */ 75 | function burn( 76 | uint256 _value 77 | ) 78 | external 79 | returns (bool success); 80 | } 81 | -------------------------------------------------------------------------------- /contracts/lib/StateRootInterface.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** @title An interface to an get state root. */ 24 | interface StateRootInterface { 25 | 26 | /** 27 | * @notice Gets the block number of latest committed state root. 28 | * 29 | * @return height_ Block height of the latest committed state root. 30 | */ 31 | function getLatestStateRootBlockHeight() 32 | external 33 | view 34 | returns (uint256 height_); 35 | 36 | /** 37 | * @notice Get the state root for the given block height. 38 | * 39 | * @param _blockHeight The block height for which the state root is fetched. 40 | * 41 | * @return bytes32 State root at the given height. 42 | */ 43 | function getStateRoot(uint256 _blockHeight) 44 | external 45 | view 46 | returns (bytes32 stateRoot_); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /contracts/test/EIP20StandardToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../gateway/EIP20Token.sol"; 24 | 25 | /** 26 | * @title EIP20StandardToken is a standard implementation of an ERC20 token. 27 | * 28 | * @notice It is required for integration tests. 29 | */ 30 | contract EIP20StandardToken is EIP20Token { 31 | 32 | /* Constructor */ 33 | 34 | /** 35 | * @notice The initial supply will be transferred to msg.sender. 36 | * 37 | * @param _symbol Symbol of the token. 38 | * @param _name Name of the token. 39 | * @param _totalSupply Total supply of the tokens at creation. Including 40 | * decimals. 41 | * @param _decimals Decimal places of the token. 42 | */ 43 | constructor( 44 | string memory _symbol, 45 | string memory _name, 46 | uint256 _totalSupply, 47 | uint8 _decimals 48 | ) 49 | public 50 | EIP20Token( 51 | _symbol, 52 | _name, 53 | _decimals 54 | ) 55 | { 56 | totalTokenSupply = _totalSupply; 57 | balances[msg.sender] = totalTokenSupply; 58 | 59 | emit Transfer(address(0), msg.sender, totalTokenSupply); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/test/anchor/MockAnchor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "../../anchor/Anchor.sol"; 4 | 5 | /** 6 | * @title MockAnchor contract. 7 | * 8 | * @notice Used for test only. 9 | */ 10 | contract MockAnchor is Anchor { 11 | 12 | /* Public functions */ 13 | 14 | /** 15 | * @notice Contract constructor. 16 | * 17 | * @param _remoteChainId The chain id of the chain that is tracked by this 18 | * anchor. 19 | * @param _blockHeight Block height at which _stateRoot needs to store. 20 | * @param _stateRoot State root hash of given _blockHeight. 21 | * @param _maxStateRoots The max number of state roots to store in the 22 | * circular buffer. 23 | * @param _organization Address of an organization contract. 24 | */ 25 | constructor( 26 | uint256 _remoteChainId, 27 | uint256 _blockHeight, 28 | bytes32 _stateRoot, 29 | uint256 _maxStateRoots, 30 | OrganizationInterface _organization 31 | ) 32 | Anchor( 33 | _remoteChainId, 34 | _blockHeight, 35 | _stateRoot, 36 | _maxStateRoots, 37 | _organization 38 | ) 39 | public 40 | {} 41 | 42 | /** 43 | * @notice Get the mocked state root. 44 | * 45 | * @dev This is for testing only so the data is mocked here. Also please 46 | * note the Anchor contract has defined this function as view, 47 | * so to keep this overridden function as view, reading a storage 48 | * variable. 49 | * 50 | * @return bytes32 Mocked state root. 51 | */ 52 | function getStateRoot(uint256) 53 | external 54 | view 55 | returns (bytes32) 56 | { 57 | // Hashing dummy data. 58 | return keccak256(abi.encodePacked("dummy data")); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /contracts/test/core/MockPollingPlace.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../../core/BlockStoreInterface.sol"; 24 | 25 | /** @title The Mock polling place contract. */ 26 | contract MockPollingPlace { 27 | 28 | /** Auxiliary block store address. */ 29 | BlockStoreInterface public auxiliaryBlockStore; 30 | 31 | /** 32 | * @notice Set the mock auxiliary block store address. 33 | * 34 | * @param _auxiliaryBlockStore Auxiliary block store contract address. 35 | */ 36 | function setAuxiliaryBlockStore(BlockStoreInterface _auxiliaryBlockStore) 37 | external 38 | { 39 | auxiliaryBlockStore = _auxiliaryBlockStore; 40 | } 41 | 42 | /** 43 | * @notice Mock the behaviour of `updateMetaBlock` function. 44 | * 45 | * @return `true` Mock result. 46 | */ 47 | function updateMetaBlock( 48 | address[] calldata, 49 | uint256[] calldata, 50 | uint256, 51 | uint256 52 | ) 53 | external 54 | pure 55 | returns (bool) 56 | { 57 | return true; 58 | } 59 | 60 | /** 61 | * @notice function `justify` in auxiliary block store can be called only 62 | * by polling place. The auxiliary block store has to be a contract 63 | * and cannot be a dummy address. This is because function 64 | * `updateMetaBlock` is called from auxiliary block store 65 | * when justify is called. So this function is used to delegate the 66 | * justify call from polling place. 67 | * 68 | * @param _sourceBlockHash The block hash of the source of the super- 69 | * majority link. 70 | * @param _targetBlockHash The block hash of the block that is justified. 71 | */ 72 | function justify( 73 | bytes32 _sourceBlockHash, 74 | bytes32 _targetBlockHash 75 | ) 76 | external 77 | { 78 | auxiliaryBlockStore.justify(_sourceBlockHash, _targetBlockHash); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /contracts/test/core/TestKernelGatewayFail.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "./TestKernelGateway.sol"; 24 | 25 | /** @title This is used to test the failed scenarios of merkle proof. */ 26 | contract TestKernelGatewayFail is TestKernelGateway{ 27 | 28 | /* Constructor */ 29 | 30 | /** 31 | * @notice Initializes the contract with origin and auxiliary block store 32 | * addresses. 33 | * 34 | * @param _mosaicCore The address of MosaicCore contract. 35 | * @param _originBlockStore The block store that stores the origin chain. 36 | * @param _auxiliaryBlockStore The block store that stores the auxiliary 37 | * chain. 38 | * @param _kernelHash Initial kernel hash. 39 | */ 40 | constructor ( 41 | address _mosaicCore, 42 | BlockStoreInterface _originBlockStore, 43 | BlockStoreInterface _auxiliaryBlockStore, 44 | bytes32 _kernelHash 45 | ) 46 | TestKernelGateway( 47 | _mosaicCore, 48 | _originBlockStore, 49 | _auxiliaryBlockStore, 50 | _kernelHash 51 | ) 52 | public 53 | { 54 | 55 | } 56 | 57 | 58 | /** 59 | * @notice Mocks the verify function of merkle patricia proof. 60 | * 61 | * @return success_ `false` to mock the failing scenario. 62 | */ 63 | function verify( 64 | bytes32, 65 | bytes memory, 66 | bytes memory, 67 | bytes32 68 | ) 69 | internal 70 | pure 71 | returns (bool success_) 72 | { 73 | success_ = false; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /contracts/test/gateway/MockEIP20CoGateway.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../../utilitytoken/contracts/CoGatewayUtilityTokenInterface.sol"; 24 | 25 | /** 26 | * @title MockEIP20CoGateway contract. 27 | * 28 | * @notice This contract mocks the EIP20CoGateway. This is used only for testing. 29 | */ 30 | contract MockEIP20CoGateway is CoGatewayUtilityTokenInterface { 31 | 32 | /** Stores the utility token address for testing. */ 33 | address private utilityTokenAddress; 34 | 35 | /** 36 | * @notice Set the utility token address for testing. 37 | * 38 | * @param _utilityToken Utility token address. 39 | */ 40 | function setUtilityToken(address _utilityToken) external { 41 | utilityTokenAddress = _utilityToken; 42 | } 43 | 44 | /** 45 | * @notice Get the utility token address. This is mock function for testing. 46 | * 47 | * @return utilityToken_ Mocked utility token address 48 | */ 49 | function utilityToken() 50 | public 51 | returns (address utilityToken_) 52 | { 53 | utilityToken_ = utilityTokenAddress; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /contracts/test/gateway/MockEIP20Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // Utility chain: MockEIP20Token.sol 19 | // 20 | // http://www.simpletoken.org/ 21 | // 22 | // ---------------------------------------------------------------------------- 23 | 24 | import "../../gateway/EIP20Token.sol"; 25 | 26 | /** 27 | * @title MockEIP20Token contract. 28 | * 29 | * @notice Implements mock totalSupply function and wraps internal 30 | * functions to enable testing EIP20Token. 31 | */ 32 | contract MockEIP20Token is EIP20Token { 33 | 34 | /* Public functions */ 35 | 36 | /** 37 | * @notice Contract constructor. 38 | * 39 | * @param _symbol Symbol of the token. 40 | * @param _name Name of the token. 41 | * @param _decimals Decimal places of the token. 42 | */ 43 | constructor( 44 | string memory _symbol, 45 | string memory _name, 46 | uint8 _decimals 47 | ) 48 | EIP20Token(_symbol, _name, _decimals) 49 | public 50 | {} 51 | 52 | /** 53 | * @notice Public view function totalSupply. 54 | * 55 | * @dev Mock totalSupply function. 56 | * 57 | * @return uint256 0 as mock total supply value. 58 | */ 59 | function totalSupply() public view returns (uint256) { 60 | return 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /contracts/test/gateway/MockRedeemerProxy.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** 24 | * @title MockRedeemerProxy is a contract used for unit testing of RedeemPool 25 | * method `destructStakerProxy`. 26 | */ 27 | contract MockRedeemerProxy { 28 | 29 | /* Storage */ 30 | 31 | /** Flag to assert if self destruct is called. */ 32 | bool public selfDestruted; 33 | 34 | 35 | /* Special Functions */ 36 | 37 | constructor () public { 38 | selfDestruted = false; 39 | } 40 | 41 | /** 42 | * @notice Mock method called from redeem pool during unit testing of 43 | * `destructRedeemerProxy`. 44 | */ 45 | function selfDestruct() external { 46 | selfDestruted = true; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /contracts/test/gateway/MockStakerProxy.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** 24 | * @title MockStakerProxy is a contract used for unit testing of ostComposer 25 | * method `destructStakerProxy`. 26 | */ 27 | contract MockStakerProxy { 28 | 29 | /* Storage */ 30 | 31 | /** Flag to assert if self destruct is called. */ 32 | bool public selfDestruted; 33 | 34 | 35 | /* Special Functions */ 36 | 37 | constructor () public { 38 | selfDestruted = false; 39 | } 40 | 41 | /** 42 | * @notice Mock method called from ost composer during unit testing of 43 | * `destructStakerProxy`. 44 | */ 45 | function selfDestruct() external { 46 | selfDestruted = true; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /contracts/test/gateway/MockTokenConfig.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // Contracts: MockTokenConfig 19 | // 20 | // http://www.simpletoken.org/ 21 | // 22 | // ---------------------------------------------------------------------------- 23 | 24 | 25 | contract MockTokenConfig { 26 | 27 | string public constant TOKEN_SYMBOL = "MOCK"; 28 | string public constant TOKEN_NAME = "Mock Token"; 29 | } 30 | -------------------------------------------------------------------------------- /contracts/test/gateway/SpyEIP20CoGateway.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "./SpyToken.sol"; 24 | 25 | /** 26 | * @title A test double co-gateway where you can check sent values. 27 | * 28 | * @notice Use this spy if you need to investigate which values were sent to 29 | * the co-gateway. 30 | */ 31 | contract SpyEIP20CoGateway { 32 | 33 | SpyToken public utilityToken; 34 | uint256 public expectedNonce = 1; 35 | uint256 public bounty = 100; 36 | uint256 public amount; 37 | address public beneficiary; 38 | uint256 public gasPrice; 39 | uint256 public gasLimit; 40 | uint256 public nonce; 41 | bytes32 public hashLock; 42 | 43 | constructor() public { 44 | utilityToken = new SpyToken(); 45 | } 46 | 47 | /** 48 | * This method is used for testing. It returns fix nonce. 49 | */ 50 | function getNonce(address) external view returns(uint256) { 51 | return expectedNonce; 52 | } 53 | 54 | /** 55 | * @notice Used for testing of redeem feature. This method spy on co-gateway redeem. 56 | * 57 | * 58 | * @param _amount Redeem amount that will be transferred from redeemer 59 | * account. 60 | * @param _beneficiary The address in the origin chain where the value 61 | * tok ens will be released. 62 | * @param _gasPrice Gas price that redeemer is ready to pay to get the 63 | * redeem process done. 64 | * @param _gasLimit Gas limit that redeemer is ready to pay. 65 | * @param _nonce Nonce of the redeemer address. 66 | * @param _hashLock Hash Lock provided by the facilitator. 67 | * 68 | * @return messageHash_ Hash of message. 69 | */ 70 | function redeem( 71 | uint256 _amount, 72 | address _beneficiary, 73 | uint256 _gasPrice, 74 | uint256 _gasLimit, 75 | uint256 _nonce, 76 | bytes32 _hashLock 77 | ) 78 | external 79 | payable 80 | returns(bytes32) 81 | { 82 | amount = _amount; 83 | beneficiary = _beneficiary; 84 | gasPrice = _gasPrice; 85 | gasLimit = _gasLimit; 86 | nonce = _nonce; 87 | hashLock = _hashLock; 88 | return bytes32('1'); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /contracts/test/gateway/SpyEIP20Gateway.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "./SpyToken.sol"; 24 | 25 | 26 | /** 27 | * @title A test double gateway where you can check sent values. 28 | * 29 | * @notice Use this spy if you need to investigate which values were sent to 30 | * the gateway. 31 | */ 32 | contract SpyEIP20Gateway { 33 | uint256 public bounty = 1337; 34 | uint256 public expectedNonce = 42; 35 | bytes32 public messageHash = "b"; 36 | 37 | SpyToken public token; 38 | SpyToken public baseToken; 39 | 40 | uint256 public amount; 41 | address public beneficiary; 42 | uint256 public gasPrice; 43 | uint256 public gasLimit; 44 | uint256 public nonce; 45 | bytes32 public hashLock; 46 | 47 | constructor() public { 48 | token = new SpyToken(); 49 | baseToken = new SpyToken(); 50 | } 51 | 52 | function stake( 53 | uint256 _amount, 54 | address _beneficiary, 55 | uint256 _gasPrice, 56 | uint256 _gasLimit, 57 | uint256 _nonce, 58 | bytes32 _hashLock 59 | ) 60 | external 61 | returns (bytes32 messageHash_) 62 | { 63 | amount = _amount; 64 | beneficiary = _beneficiary; 65 | gasPrice = _gasPrice; 66 | gasLimit = _gasLimit; 67 | nonce = _nonce; 68 | hashLock = _hashLock; 69 | 70 | messageHash_ = messageHash; 71 | } 72 | 73 | function getNonce(address) external view returns(uint256) { 74 | return expectedNonce; 75 | } 76 | 77 | function setBaseToken(SpyToken _baseToken) public { 78 | baseToken = _baseToken; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /contracts/test/gateway/TestOSTPrime.sol: -------------------------------------------------------------------------------- 1 | /* solhint-disable-next-line compiler-fixed */ 2 | pragma solidity ^0.5.0; 3 | 4 | // Copyright 2019 OpenST Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | // ---------------------------------------------------------------------------- 19 | // 20 | // http://www.simpletoken.org/ 21 | // 22 | // ---------------------------------------------------------------------------- 23 | 24 | // TestOSTPrime is used to test the OSTPrime contract. 25 | import "../../gateway/OSTPrime.sol"; 26 | 27 | /** @title Test OST prime contract. */ 28 | contract TestOSTPrime is OSTPrime { 29 | 30 | /* Constructor */ 31 | 32 | /** 33 | * @notice Contract constructor. 34 | * 35 | * @dev This contract is used only for testing. 36 | * 37 | * @param _valueToken ERC20 token address in origin chain. 38 | * @param _organization Address of a contract that manages organization. 39 | */ 40 | constructor( 41 | address _valueToken, 42 | OrganizationInterface _organization 43 | ) 44 | public 45 | OSTPrime(_valueToken, _organization) 46 | {} 47 | 48 | 49 | /* Public functions. */ 50 | 51 | /** 52 | * @notice Set the OST Prime token balance for the given account address. 53 | * 54 | * @dev This is used only for testing. 55 | * 56 | * @param _account Address for which the balance is to be set. 57 | * @param _amount The amount of tokens to be set. 58 | */ 59 | function setTokenBalance( 60 | address _account, 61 | uint256 _amount 62 | ) 63 | public 64 | { 65 | balances[_account] = _amount; 66 | } 67 | 68 | /** 69 | * @notice Set the CoGateway address for testing. 70 | * 71 | * @param _coGatewayAddress CoGateway address. 72 | */ 73 | function setCoGatewayAddress(address _coGatewayAddress) public { 74 | coGateway = _coGatewayAddress; 75 | } 76 | 77 | /** 78 | * @notice Set the total supply count for testing. 79 | * 80 | * @param _amount The supply amount. 81 | */ 82 | function setTotalSupply(uint256 _amount) public { 83 | totalTokenSupply = _amount; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /contracts/test/lib/MockGatewayLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | /** 4 | * @title MockGatewayLib contract 5 | * 6 | * @notice Mocks the GatewayLib library. Used only for testing. 7 | */ 8 | library MockGatewayLib { 9 | 10 | /** 11 | * @notice Mock Merkle proof verification of account. 12 | * 13 | * @return bytes32 Mocked value of storage path of the variable. 14 | */ 15 | function proveAccount( 16 | bytes calldata, 17 | bytes calldata, 18 | bytes calldata, 19 | bytes32 20 | ) 21 | external 22 | pure 23 | returns (bytes32 storageRoot_) 24 | { 25 | return bytes32(0x8c0ee0843488170879578464b1cadcdb7377efa787372405ff373e4cec6a56db); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /contracts/test/lib/MockMerklePatriciaProof.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // Auxiliary Chain: MockMerklePatriciaProof 19 | // 20 | // http://www.simpletoken.org/ 21 | // 22 | // ---------------------------------------------------------------------------- 23 | 24 | /** 25 | * @title MockMerklePatriciaProof 26 | * 27 | * @dev Library for mocking merkle patricia proofs. 28 | */ 29 | 30 | library MockMerklePatriciaProof { 31 | 32 | /** 33 | * @dev Mock for merkle patricia proof verifier. 34 | * 35 | * @return Mocked value for validity of the proof. 36 | */ 37 | function verify( 38 | bytes32, 39 | bytes calldata, 40 | bytes calldata, 41 | bytes32 42 | ) 43 | external 44 | pure 45 | returns (bool) 46 | { 47 | return true; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /contracts/test/lib/TestCircularBufferUint.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | import "../../lib/CircularBufferUint.sol"; 24 | 25 | /** 26 | * @title Test contract for the circular buffer for `uint`s. 27 | * 28 | * @notice The methods on the circular buffer are internal and therefore not 29 | * testable from the JS layer. This proxy contract wraps the original 30 | * implementation and exposes external methods which proxy the internal 31 | * methods of the circular buffer under test. 32 | */ 33 | contract TestCircularBufferUint is CircularBufferUint { 34 | 35 | /* Constructor */ 36 | 37 | /** 38 | * @notice Create a new test buffer with the size `_maxItems`. 39 | * 40 | * @param _maxItems Defines how many items this test buffer stores before 41 | * overwriting older items. 42 | */ 43 | constructor(uint256 _maxItems) public CircularBufferUint(_maxItems) {} 44 | 45 | 46 | /* Internal functions */ 47 | 48 | /** 49 | * @notice Store a new item in the circular test buffer. 50 | * 51 | * @param _item The item to store in the circular test buffer. 52 | * 53 | * @return overwrittenItem_ The item that was in the circular test buffer's 54 | * position where the new item is now stored. The 55 | * overwritten item is no longer available in the 56 | * circular test buffer. 57 | */ 58 | function storeExternal(uint256 _item) external returns(uint256 overwrittenItem_) { 59 | overwrittenItem_ = CircularBufferUint.store(_item); 60 | } 61 | 62 | /** 63 | * @notice Get the most recent item that was stored in the circular test 64 | * buffer. 65 | * 66 | * @return head_ The most recently stored item. 67 | */ 68 | function headExternal() external view returns(uint256 head_) { 69 | head_ = CircularBufferUint.head(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /contracts/truffle/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | constructor() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/OpenSTwp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/docs/OpenSTwp.pdf -------------------------------------------------------------------------------- /docs/diagrams/v092/stakemintv092.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/docs/diagrams/v092/stakemintv092.png -------------------------------------------------------------------------------- /docs/diagrams/v093/stakemint/stakemintv093.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/docs/diagrams/v093/stakemint/stakemintv093.pdf -------------------------------------------------------------------------------- /docs/mosaicv0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/docs/mosaicv0.pdf -------------------------------------------------------------------------------- /docs/protocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/docs/protocol.png -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import * as contracts from './contract_build/contracts.json'; 2 | import interacts from './interacts/Interacts'; 3 | 4 | export {contracts, interacts}; 5 | -------------------------------------------------------------------------------- /migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('./Migrations.sol'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | const MessageBus = artifacts.require('./gateway/MessageBus.sol'); 2 | const GatewayLib = artifacts.require('./gateway/GatewayLib.sol'); 3 | const GatewayBase = artifacts.require('./gateway/GatewayBase.sol'); 4 | const EIP20Gateway = artifacts.require('EIP20Gateway'); 5 | const MockGatewayLib = artifacts.require('MockGatewayLib'); 6 | const MockGatewayBase = artifacts.require('MockGatewayBase'); 7 | const TestGatewayBase = artifacts.require('TestGatewayBase'); 8 | const MetaBlock = artifacts.require('../contracts/lib/MetaBlock.sol'); 9 | const BlockStore = artifacts.require('../contracts/BlockStore.sol'); 10 | const TestEIP20Gateway = artifacts.require('TestEIP20Gateway'); 11 | const EIP20CoGateway = artifacts.require('EIP20CoGateway'); 12 | const TestEIP20CoGateway = artifacts.require('TestEIP20CoGateway'); 13 | const AuxiliaryBlockStore = artifacts.require( 14 | '../contracts/AuxiliaryBlockStore.sol', 15 | ); 16 | const MockMessageBus = artifacts.require('./gateway/MockMessageBus.sol'); 17 | const MessageBusWrapper = artifacts.require('./test/MessageBusWrapper'); 18 | const MockMerklePatriciaProof = artifacts.require('./test/MockMerklePatriciaProof'); 19 | const MerklePatriciaProofTest = artifacts.require('./MerklePatriciaProofTest'); 20 | const MerklePatriciaProof = artifacts.require('./MerklePatriciaProof'); 21 | const TestKernelGateway = artifacts.require('TestKernelGateway'); 22 | const TestKernelGatewayFail = artifacts.require('TestKernelGatewayFail'); 23 | const KernelGateway = artifacts.require('KernelGateway'); 24 | 25 | module.exports = function (deployer) { 26 | deployer.deploy(MerklePatriciaProof); 27 | 28 | deployer.link(MerklePatriciaProof, MessageBus); 29 | deployer.deploy(MessageBus); 30 | deployer.link(MessageBus, MockMessageBus); 31 | 32 | deployer.link( 33 | MerklePatriciaProof, 34 | [GatewayLib, KernelGateway, TestKernelGateway, TestKernelGatewayFail], 35 | ); 36 | 37 | deployer.deploy(GatewayLib); 38 | deployer.deploy(MockGatewayLib); 39 | deployer.deploy(MetaBlock); 40 | deployer.link(GatewayLib, [GatewayBase, TestGatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]); 41 | deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway, TestGatewayBase]); 42 | deployer.link(MockGatewayLib, [MockGatewayBase, TestEIP20Gateway]); 43 | deployer.link(MetaBlock, [BlockStore, AuxiliaryBlockStore]); 44 | 45 | deployer.deploy(MockMerklePatriciaProof); 46 | deployer.link(MockMerklePatriciaProof, [MockMessageBus]); 47 | deployer.deploy(MockMessageBus); 48 | deployer.link(MockMessageBus, MessageBusWrapper); 49 | 50 | deployer.link(MerklePatriciaProof, MerklePatriciaProofTest); 51 | }; 52 | -------------------------------------------------------------------------------- /proof_generation/docker.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const waitPort = require('wait-port'); 22 | 23 | // The port should be same as network integration_origin port defined in truffle.js 24 | const originPort = 8546; 25 | 26 | const asyncSleep = ms => new Promise(resolve => setTimeout(resolve, ms)); 27 | 28 | const docker = () => { 29 | const waitForOriginNode = waitPort({ port: originPort, output: 'silent' }); 30 | return Promise.all([waitForOriginNode]).then( 31 | // even after the ports are available the nodes need a bit of time to get online 32 | () => asyncSleep(5000), 33 | ).then(() => ({ 34 | rpcEndpointOrigin: `http://localhost:${originPort}`, 35 | })); 36 | }; 37 | 38 | module.exports = docker; 39 | -------------------------------------------------------------------------------- /proof_generation/main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT_NAME='mosaic_proof_generator' 4 | 5 | docker run --name mosaic -it -d -p 8546:8545 augurproject/dev-node-geth:v1.8.18 6 | ./node_modules/.bin/truffle --network integration_origin test proof_generation/generator.js 7 | TEST_STATUS=$? 8 | docker stop mosaic 9 | docker rm mosaic 10 | 11 | exit $TEST_STATUS 12 | -------------------------------------------------------------------------------- /test/anchor/anchor/get_latest_state_root_block_height.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const MockOrganization = artifacts.require('MockOrganization.sol'); 22 | const Anchor = artifacts.require('./Anchor.sol'); 23 | const BN = require('bn.js'); 24 | const web3 = require('../../test_lib/web3.js'); 25 | 26 | contract('Anchor.getLatestStateRootBlockHeight()', (accounts) => { 27 | let remoteChainId; 28 | let blockHeight; 29 | let stateRoot; 30 | let maxNumberOfStateRoots; 31 | let organization; 32 | let anchor; 33 | let owner; 34 | let worker; 35 | 36 | beforeEach(async () => { 37 | owner = accounts[2]; 38 | worker = accounts[3]; 39 | remoteChainId = new BN(1410); 40 | blockHeight = new BN(5); 41 | stateRoot = web3.utils.sha3('dummy_state_root'); 42 | maxNumberOfStateRoots = new BN(10); 43 | organization = await MockOrganization.new(owner, worker); 44 | 45 | anchor = await Anchor.new( 46 | remoteChainId, 47 | blockHeight, 48 | stateRoot, 49 | maxNumberOfStateRoots, 50 | organization.address, 51 | ); 52 | }); 53 | 54 | it('should return the state root that was set while deployment', async () => { 55 | const latestBlockHeight = await anchor.getLatestStateRootBlockHeight.call(); 56 | assert.strictEqual( 57 | blockHeight.eq(latestBlockHeight), 58 | true, 59 | `Latest block height from the contract must be ${blockHeight}.`, 60 | ); 61 | }); 62 | 63 | it('should return the latest anchored state root block height', async () => { 64 | blockHeight = blockHeight.addn(50000); 65 | 66 | await anchor.anchorStateRoot(blockHeight, stateRoot, { from: owner }); 67 | 68 | const latestBlockHeight = await anchor.getLatestStateRootBlockHeight.call(); 69 | assert.strictEqual( 70 | blockHeight.eq(latestBlockHeight), 71 | true, 72 | `Latest block height from the contract must be ${blockHeight}.`, 73 | ); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/anchor/anchor/get_remote_chainId.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const Anchor = artifacts.require('./Anchor.sol'); 22 | const BN = require('bn.js'); 23 | const web3 = require('../../test_lib/web3.js'); 24 | 25 | contract('Anchor.getRemoteChainId()', (accounts) => { 26 | let remoteChainId; 27 | let blockHeight; 28 | let stateRoot; 29 | let maxNumberOfStateRoots; 30 | let organization; 31 | let anchor; 32 | 33 | beforeEach(async () => { 34 | remoteChainId = new BN(1410); 35 | blockHeight = new BN(5); 36 | stateRoot = web3.utils.sha3('dummy_state_root'); 37 | maxNumberOfStateRoots = new BN(10); 38 | organization = accounts[1]; 39 | 40 | anchor = await Anchor.new( 41 | remoteChainId, 42 | blockHeight, 43 | stateRoot, 44 | maxNumberOfStateRoots, 45 | organization, 46 | ); 47 | }); 48 | 49 | it('should return correct remote chain id', async () => { 50 | const chainId = await anchor.getRemoteChainId.call(); 51 | assert.strictEqual( 52 | remoteChainId.eq(chainId), 53 | true, 54 | `Remote chain id from the contract must be ${remoteChainId}.`, 55 | ); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /test/anchor/anchor/get_state_root.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const MockOrganization = artifacts.require('MockOrganization.sol'); 22 | const Anchor = artifacts.require('./Anchor.sol'); 23 | const BN = require('bn.js'); 24 | const web3 = require('../../test_lib/web3.js'); 25 | const Utils = require('../../test_lib/utils.js'); 26 | 27 | const zeroBytes = Utils.ZERO_BYTES32; 28 | 29 | contract('Anchor.getStateRoot()', (accounts) => { 30 | let remoteChainId; 31 | let blockHeight; 32 | let stateRoot; 33 | let maxNumberOfStateRoots; 34 | let organization; 35 | let anchor; 36 | let owner; 37 | let worker; 38 | 39 | beforeEach(async () => { 40 | owner = accounts[2]; 41 | worker = accounts[3]; 42 | remoteChainId = new BN(1410); 43 | blockHeight = new BN(5); 44 | stateRoot = web3.utils.sha3('dummy_state_root'); 45 | maxNumberOfStateRoots = new BN(10); 46 | organization = await MockOrganization.new(owner, worker); 47 | 48 | anchor = await Anchor.new( 49 | remoteChainId, 50 | blockHeight, 51 | stateRoot, 52 | maxNumberOfStateRoots, 53 | organization.address, 54 | ); 55 | }); 56 | 57 | it( 58 | 'should return the latest state root block height that was set ' 59 | + 'while deployment', 60 | async () => { 61 | const latestStateRoot = await anchor.getStateRoot.call(blockHeight); 62 | assert.strictEqual( 63 | latestStateRoot, 64 | stateRoot, 65 | `Latest state root from the contract must be ${stateRoot}.`, 66 | ); 67 | }, 68 | ); 69 | 70 | it('should return the zero bytes for non anchored block heights', async () => { 71 | blockHeight = blockHeight.addn(500); 72 | 73 | const latestStateRoot = await anchor.getStateRoot.call(blockHeight); 74 | assert.strictEqual( 75 | latestStateRoot, 76 | zeroBytes, 77 | `Latest state root from the contract must be ${zeroBytes}.`, 78 | ); 79 | }); 80 | 81 | it('should return the latest anchored state root', async () => { 82 | blockHeight = blockHeight.addn(50000); 83 | stateRoot = web3.utils.sha3('dummy_state_root_1'); 84 | 85 | await anchor.anchorStateRoot(blockHeight, stateRoot, { from: owner }); 86 | 87 | const latestStateRoot = await anchor.getStateRoot.call(blockHeight); 88 | assert.strictEqual( 89 | latestStateRoot, 90 | stateRoot, 91 | `Latest state root from the contract must be ${stateRoot}.`, 92 | ); 93 | }); 94 | }); 95 | -------------------------------------------------------------------------------- /test/core/auxiliary_block_store/initialize_kernel_gateway.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const Utils = require('../../test_lib/utils.js'); 23 | 24 | const AuxiliaryBlockStore = artifacts.require('AuxiliaryBlockStore'); 25 | 26 | contract('AuxiliaryBlockStore.initialize()', async (accounts) => { 27 | const zeroAddress = Utils.NULL_ADDRESS; 28 | 29 | let auxiliaryBlockStore; 30 | 31 | beforeEach(async () => { 32 | const initialKernelHash = web3.utils.sha3('kernelHash'); 33 | auxiliaryBlockStore = await AuxiliaryBlockStore.new( 34 | '0x0000000000000000000000000000000000000001', 35 | 10, 36 | accounts[0], 37 | accounts[1], 38 | '0x7f1034f3d32a11c606f8ae8265344d2ab06d71500289df6f9cac2e013990830c', 39 | '0xb6a85955e3671040901a17db85b121550338ad1a0071ca13d196d19df31f56ca', 40 | 0, 41 | new BN('21000'), 42 | '0x5fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67', 43 | initialKernelHash, 44 | ); 45 | }); 46 | 47 | it('should fail when gateway address is zero', async () => { 48 | await Utils.expectRevert( 49 | auxiliaryBlockStore.initialize.call(zeroAddress), 50 | 'Kernel gateway address must not be zero.', 51 | ); 52 | }); 53 | 54 | it('should set kernel gateway address its not already set', async () => { 55 | await auxiliaryBlockStore.initialize(accounts[2]); 56 | 57 | const gatewayKernelAddress = await auxiliaryBlockStore.kernelGateway.call(); 58 | 59 | assert.strictEqual( 60 | gatewayKernelAddress, 61 | accounts[2], 62 | `Kernel gateway address must be ${accounts[2]}.`, 63 | ); 64 | }); 65 | 66 | it('should fail when gateway address is already initialized', async () => { 67 | await auxiliaryBlockStore.initialize(accounts[2]); 68 | 69 | await Utils.expectRevert( 70 | auxiliaryBlockStore.initialize.call(accounts[2]), 71 | 'Kernel gateway must not be already initialized.', 72 | ); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/core/kernel_gateway/get_active_kernel_hash.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const web3 = require('../../test_lib/web3.js'); 22 | 23 | const KernelGateway = artifacts.require('TestKernelGateway'); 24 | const MockBlockStore = artifacts.require('MockBlockStore'); 25 | 26 | contract('KernelGateway.getActiveKernelHash()', async (accounts) => { 27 | let kernelGateway; 28 | let originBlockStore; 29 | let auxiliaryBlockStore; 30 | let initialKernelHash; 31 | 32 | beforeEach(async () => { 33 | initialKernelHash = web3.utils.sha3('kernelHash'); 34 | originBlockStore = await MockBlockStore.new(); 35 | auxiliaryBlockStore = await MockBlockStore.new(); 36 | 37 | kernelGateway = await KernelGateway.new( 38 | accounts[1], 39 | originBlockStore.address, 40 | auxiliaryBlockStore.address, 41 | initialKernelHash, 42 | ); 43 | 44 | await auxiliaryBlockStore.setKernelGateway(kernelGateway.address); 45 | }); 46 | 47 | it('should return initial kernel hash', async () => { 48 | const activeKernelHash = await kernelGateway.getActiveKernelHash.call(); 49 | 50 | assert.strictEqual( 51 | activeKernelHash, 52 | initialKernelHash, 53 | 'The contract did not return initial kernel hash.', 54 | ); 55 | }); 56 | 57 | it('should return correct kernel hash', async () => { 58 | const hash = '0xb6a85955e3671040901a17db85b121550338ad1a0071ca13d196d19df31f56ca'; 59 | 60 | await kernelGateway.setOpenKernelHash(hash); 61 | 62 | await auxiliaryBlockStore.activateKernel(hash); 63 | 64 | const activeKernelHash = await kernelGateway.getActiveKernelHash.call(); 65 | 66 | assert.strictEqual( 67 | activeKernelHash, 68 | hash, 69 | 'The contract did not return correct hash.', 70 | ); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /test/core/mosaic_core/get_accumulated_gas_target.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | const BN = require('bn.js'); 21 | const web3 = require('../../test_lib/web3.js'); 22 | 23 | const MosaicCore = artifacts.require('MosaicCore'); 24 | 25 | contract('MosaicCore.getAccumulatedGasTarget()', async (accounts) => { 26 | /** 27 | * @dev while writing this test commitMetaBlock function is not 28 | * implemented, So once its updated the tests should be updated to use 29 | * commitMetaBlock function. Currently this tests are using the genesis 30 | * meta block for testing 31 | */ 32 | 33 | let mosaicCore; 34 | let maxAccumulateGasLimit; 35 | let gas; 36 | let auxiliaryCoreIdentifier; 37 | let transactionRoot; 38 | let ost; 39 | let minimumWeight; 40 | 41 | /** Deploys the mosaic core contract */ 42 | async function deployMosaicCore() { 43 | mosaicCore = await MosaicCore.new( 44 | auxiliaryCoreIdentifier, 45 | ost, 46 | gas, 47 | transactionRoot, 48 | minimumWeight, 49 | maxAccumulateGasLimit, 50 | ); 51 | } 52 | 53 | /** Asserts the accumulated gas target */ 54 | async function testAccumulatedGasTarget() { 55 | await deployMosaicCore(); 56 | const accumulatedGasTarget = await mosaicCore.getAccumulatedGasTarget.call(); 57 | assert( 58 | accumulatedGasTarget.eq(gas.add(maxAccumulateGasLimit)), 59 | 'Accumulated gas target should' 60 | + `be ${gas.add(maxAccumulateGasLimit).toString(10)}`, 61 | ); 62 | } 63 | 64 | beforeEach(async () => { 65 | auxiliaryCoreIdentifier = web3.utils.sha3('1'); 66 | transactionRoot = web3.utils.sha3('1'); 67 | ost = accounts[0]; 68 | minimumWeight = new BN('1'); 69 | }); 70 | 71 | it('should return 200 as accumulate gas target', async () => { 72 | gas = new BN('100'); 73 | maxAccumulateGasLimit = new BN('100'); 74 | await testAccumulatedGasTarget(); 75 | }); 76 | 77 | it('should return 1245 as accumulate gas target', async () => { 78 | gas = new BN('245'); 79 | maxAccumulateGasLimit = new BN('1000'); 80 | await testAccumulatedGasTarget(); 81 | }); 82 | }); 83 | -------------------------------------------------------------------------------- /test/core/mosaic_core/get_latest_state_root_block_height.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | const BN = require('bn.js'); 21 | const web3 = require('../../test_lib/web3.js'); 22 | 23 | const MosaicCore = artifacts.require('TestMosaicCore'); 24 | 25 | /** 26 | * @dev This test just verifies the value of variable is 27 | * latestStateRootBlockHeight returned by the 28 | * `getLatestStateRootBlockHeight()`. 29 | */ 30 | 31 | contract('MosaicCore.getLatestStateRootBlockHeight()', async (accounts) => { 32 | const coreIdentifier = '0x0000000000000000000000000000000000000001'; 33 | 34 | const gas = new BN('100'); 35 | const maxAccumulateGasLimit = new BN('100'); 36 | const transactionRoot = web3.utils.sha3('1'); 37 | const minimumWeight = new BN('1'); 38 | 39 | let mosaicCore; 40 | let ost; 41 | 42 | /** Deploys the mosaic core contract */ 43 | async function deployMosaicCore() { 44 | mosaicCore = await MosaicCore.new( 45 | coreIdentifier, 46 | ost, 47 | gas, 48 | transactionRoot, 49 | minimumWeight, 50 | maxAccumulateGasLimit, 51 | ); 52 | } 53 | 54 | beforeEach(async () => { 55 | ost = accounts[0]; 56 | await deployMosaicCore(); 57 | }); 58 | 59 | it('should return zero.', async () => { 60 | const latestStateRootBlockHeight = await mosaicCore.getLatestStateRootBlockHeight.call(); 61 | 62 | assert( 63 | latestStateRootBlockHeight.eq(new BN(0)), 64 | 'The latest height from the contract must be zero.', 65 | ); 66 | }); 67 | 68 | it('should return latestStateRootBlockHeight variable value.', async () => { 69 | const height = new BN(1234); 70 | await mosaicCore.setLatestStateRootBlockHeight(height); 71 | 72 | const latestStateRootBlockHeight = await mosaicCore.getLatestStateRootBlockHeight.call(); 73 | 74 | assert( 75 | latestStateRootBlockHeight.eq(height), 76 | `State root from the contract must be ${height}.`, 77 | ); 78 | }); 79 | }); 80 | -------------------------------------------------------------------------------- /test/core/mosaic_core/get_storage_root.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | const BN = require('bn.js'); 21 | const web3 = require('../../test_lib/web3.js'); 22 | const Utils = require('../../test_lib/utils.js'); 23 | 24 | const MosaicCore = artifacts.require('TestMosaicCore'); 25 | 26 | /** 27 | * @dev This test just verifies the value returned by function 28 | * `getStateRoot()` is from `stateRoots` variable. 29 | */ 30 | 31 | contract('MosaicCore.getStorageRoot()', async (accounts) => { 32 | const coreIdentifier = '0x0000000000000000000000000000000000000001'; 33 | const zeroBytes = Utils.ZERO_BYTES32; 34 | 35 | const gas = new BN('100'); 36 | const maxAccumulateGasLimit = new BN('100'); 37 | const transactionRoot = web3.utils.sha3('1'); 38 | const minimumWeight = new BN('1'); 39 | 40 | let mosaicCore; 41 | let ost; 42 | 43 | /** Deploys the mosaic core contract */ 44 | async function deployMosaicCore() { 45 | mosaicCore = await MosaicCore.new( 46 | coreIdentifier, 47 | ost, 48 | gas, 49 | transactionRoot, 50 | minimumWeight, 51 | maxAccumulateGasLimit, 52 | ); 53 | } 54 | 55 | beforeEach(async () => { 56 | ost = accounts[0]; 57 | await deployMosaicCore(); 58 | }); 59 | 60 | it('should return zero bytes when the data does not exists.', async () => { 61 | const height = new BN(1); 62 | const stateRoot = await mosaicCore.getStateRoot.call(height); 63 | 64 | assert.strictEqual( 65 | stateRoot, 66 | zeroBytes, 67 | 'State root from the contract must be zero.', 68 | ); 69 | }); 70 | 71 | it('should return correct bytes when state root exists.', async () => { 72 | const height = new BN(1); 73 | const stateRoot = web3.utils.sha3('stateRoot'); 74 | await mosaicCore.setStateRoot(height, stateRoot); 75 | 76 | const cStateRoot = await mosaicCore.getStateRoot.call(height); 77 | 78 | assert.strictEqual( 79 | cStateRoot, 80 | stateRoot, 81 | `State root from the contract must be ${stateRoot}.`, 82 | ); 83 | }); 84 | }); 85 | -------------------------------------------------------------------------------- /test/core/stake/close_meta_block.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const config = require('../../test_lib/config.js'); 23 | const Events = require('../../test_lib/event_decoder.js'); 24 | const StakeUtils = require('./helpers/stake_utils.js'); 25 | const Utils = require('../../test_lib/utils.js'); 26 | 27 | const MockToken = artifacts.require('MockToken'); 28 | const Stake = artifacts.require('Stake'); 29 | 30 | contract('Stake.closeMetaBlock()', async (accounts) => { 31 | const mosaicCoreAccount = accounts[1]; 32 | const minimumWeight = new BN('1'); 33 | let token; 34 | let stake; 35 | 36 | beforeEach(async () => { 37 | token = await MockToken.new(config.decimals); 38 | stake = await Stake.new(token.address, mosaicCoreAccount, minimumWeight); 39 | await StakeUtils.initializeStake( 40 | stake, 41 | token, 42 | accounts[0], 43 | [accounts[2]], 44 | [new BN('2')], 45 | ); 46 | }); 47 | 48 | it('should increase the meta-block height by 1', async () => { 49 | for (let expectedHeight = 2; expectedHeight < 5; expectedHeight++) { 50 | await stake.closeMetaBlock(new BN(expectedHeight - 1), { 51 | from: mosaicCoreAccount, 52 | }); 53 | 54 | height = await stake.height.call(); 55 | assert.strictEqual( 56 | expectedHeight, 57 | height.toNumber(), 58 | 'The height should increase by one when an meta-block is closed.', 59 | ); 60 | } 61 | }); 62 | 63 | it('should emit an event when an meta-block is closed', async () => { 64 | let tx = await stake.closeMetaBlock(new BN(1), { 65 | from: mosaicCoreAccount, 66 | }); 67 | let events = Events.perform(tx.receipt, stake.address, stake.abi); 68 | assert.strictEqual( 69 | Number(events.HeightIncreased.newHeight), 70 | 2, 71 | 'The contract did not emit an event with the new height.', 72 | ); 73 | 74 | tx = await stake.closeMetaBlock(new BN(2), { from: mosaicCoreAccount }); 75 | events = Events.perform(tx.receipt, stake.address, stake.abi); 76 | assert.strictEqual( 77 | Number(events.HeightIncreased.newHeight), 78 | 3, 79 | 'The contract did not emit an event with the new height.', 80 | ); 81 | }); 82 | 83 | it('should fail when a wrong height is given', async () => { 84 | await Utils.expectFailedAssert( 85 | stake.closeMetaBlock(new BN(3), { from: mosaicCoreAccount }), 86 | ); 87 | }); 88 | }); 89 | -------------------------------------------------------------------------------- /test/core/stake/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const Utils = require('../../test_lib/utils.js'); 23 | 24 | const Stake = artifacts.require('Stake'); 25 | 26 | contract('Stake.constructor()', async (accounts) => { 27 | const tokenAddress = accounts[3]; 28 | const mosaicCoreAddress = accounts[4]; 29 | const zeroAddress = Utils.NULL_ADDRESS; 30 | 31 | it('should accept a correct construction', async () => { 32 | await Stake.new(tokenAddress, mosaicCoreAddress, new BN('1000')); 33 | }); 34 | 35 | it('should reject a zero token address', async () => { 36 | await Utils.expectRevert( 37 | Stake.new(zeroAddress, mosaicCoreAddress, new BN('10')), 38 | 'The address of the staking token must not be zero.', 39 | ); 40 | }); 41 | 42 | it('should reject a zero mosaic core address', async () => { 43 | await Utils.expectRevert( 44 | Stake.new(tokenAddress, zeroAddress, new BN('10')), 45 | 'The address of the mosaic core must not be zero.', 46 | ); 47 | }); 48 | 49 | it('should reject a zero minimum weight', async () => { 50 | await Utils.expectRevert( 51 | Stake.new(tokenAddress, mosaicCoreAddress, new BN('0')), 52 | 'Minimum weight must be greater than zero.', 53 | ); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /test/gateway/eip20_cogateway/helpers/co_gateway_utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | const web3 = require('../../../test_lib/web3.js'); 24 | const utils = require('../../../test_lib/utils.js'); 25 | 26 | class CoGatewayUtils { 27 | /** 28 | * Generate the redeem intent hash 29 | * 30 | * @param {object} amount Redeem amount. 31 | * @param {string} beneficiary Beneficiary address. 32 | * @param {string} gateway The address of the gateway where the redemption was 33 | * initiated. 34 | * 35 | * @return {string} redeem intent hash. 36 | */ 37 | static hashRedeemIntent(amount, beneficiary, gateway) { 38 | const redeemIntentTypeHash = utils.getTypeHash( 39 | 'RedeemIntent(uint256 amount,address beneficiary,address gateway)', 40 | ); 41 | 42 | const redeemIntent = web3.utils.sha3( 43 | web3.eth.abi.encodeParameters( 44 | ['bytes32', 'uint256', 'address', 'address'], 45 | [redeemIntentTypeHash, amount.toString(10), beneficiary, gateway], 46 | ), 47 | ); 48 | 49 | return redeemIntent; 50 | } 51 | 52 | /** 53 | * Generate the stake intent hash 54 | * 55 | * @param {object} amount Staking amount. 56 | * @param {string} beneficiary Beneficiary address. 57 | * @param {string} gateway The address of the gateway where the staking was 58 | * initiated. 59 | * 60 | * @return {string} stake intent hash. 61 | */ 62 | static hashStakeIntent(amount, beneficiary, gateway) { 63 | const stakeIntentTypeHash = utils.getTypeHash( 64 | 'StakeIntent(uint256 amount,address beneficiary,address gateway)', 65 | ); 66 | 67 | const stakeIntent = web3.utils.sha3( 68 | web3.eth.abi.encodeParameters( 69 | ['bytes32', 'uint256', 'address', 'address'], 70 | [stakeIntentTypeHash, amount.toNumber(), beneficiary, gateway], 71 | ), 72 | ); 73 | 74 | return stakeIntent; 75 | } 76 | } 77 | 78 | module.exports = CoGatewayUtils; 79 | -------------------------------------------------------------------------------- /test/gateway/eip20_gateway/deactivate_gateway.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const Utils = require('../../../test/test_lib/utils'); 23 | 24 | const Gateway = artifacts.require('./EIP20Gateway.sol'); 25 | const MockOrganization = artifacts.require('MockOrganization.sol'); 26 | 27 | const NullAddress = Utils.NULL_ADDRESS; 28 | 29 | contract('EIP20Gateway.deactivateGateway()', (accounts) => { 30 | const owner = accounts[2]; 31 | const worker = accounts[3]; 32 | const coGateway = accounts[5]; 33 | const burner = NullAddress; 34 | 35 | let gateway; 36 | let organization; 37 | 38 | beforeEach(async () => { 39 | const [mockToken, baseToken, dummyStateRootProvider] = accounts; 40 | const bountyAmount = new BN(100); 41 | 42 | organization = await MockOrganization.new(owner, worker); 43 | 44 | gateway = await Gateway.new( 45 | mockToken, 46 | baseToken, 47 | dummyStateRootProvider, 48 | bountyAmount, 49 | organization.address, 50 | burner, 51 | new BN(100), 52 | ); 53 | 54 | await gateway.activateGateway(coGateway, { from: owner }); 55 | }); 56 | 57 | it('should deactivate if activated', async () => { 58 | const isSuccess = await gateway.deactivateGateway.call({ from: owner }); 59 | 60 | assert.strictEqual( 61 | isSuccess, 62 | true, 63 | 'Gateway deactivation failed, deactivateGateway returned false.', 64 | ); 65 | 66 | await gateway.deactivateGateway({ from: owner }); 67 | const isActivated = await gateway.activated.call(); 68 | 69 | assert.strictEqual( 70 | isActivated, 71 | false, 72 | 'Activation flag is true but expected as false.', 73 | ); 74 | }); 75 | 76 | it('should not deactivate if already deactivated', async () => { 77 | await gateway.deactivateGateway({ from: owner }); 78 | await Utils.expectRevert( 79 | gateway.deactivateGateway.call({ from: owner }), 80 | 'Gateway is already deactivated.', 81 | ); 82 | }); 83 | 84 | it('should deactivated by organization only', async () => { 85 | await Utils.expectRevert( 86 | gateway.deactivateGateway.call({ from: accounts[0] }), 87 | 'Only the organization is allowed to call this method.', 88 | ); 89 | }); 90 | }); 91 | -------------------------------------------------------------------------------- /test/gateway/gateway_base/get_nonce.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | 23 | const GatewayBase = artifacts.require('./GatewayBase.sol'); 24 | const MockOrganization = artifacts.require('MockOrganization.sol'); 25 | 26 | /* 27 | * The tests that assert that the nonce increases when staking or redeeming are 28 | * in the respective test files for stake and redeem. 29 | */ 30 | 31 | contract('GatewayBase.sol', (accounts) => { 32 | describe('get nonce', async () => { 33 | let gatewayBaseInstance; 34 | 35 | beforeEach(async () => { 36 | const owner = accounts[2]; 37 | const worker = accounts[3]; 38 | const dummyStateRootProviderAddress = accounts[0]; 39 | const bounty = new BN(100); 40 | 41 | const organization = await MockOrganization.new(owner, worker); 42 | 43 | gatewayBaseInstance = await GatewayBase.new( 44 | dummyStateRootProviderAddress, 45 | bounty, 46 | organization.address, 47 | new BN(100), 48 | ); 49 | }); 50 | 51 | it('should return nonce `0` if there is no active process', async () => { 52 | const expectedNonce = new BN(0); 53 | const nonce = await gatewayBaseInstance.getNonce.call(accounts[0]); 54 | assert(nonce.eq(expectedNonce)); 55 | }); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /test/gateway/message_bus/declare_revocation_message.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/test/gateway/message_bus/declare_revocation_message.js -------------------------------------------------------------------------------- /test/gateway/message_bus/progress_inbox.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/test/gateway/message_bus/progress_inbox.js -------------------------------------------------------------------------------- /test/gateway/message_bus/verify_signature.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenST/mosaic-contracts/40fadf598b4b3c1920ef520841081632825554b7/test/gateway/message_bus/verify_signature.js -------------------------------------------------------------------------------- /test/gateway/mock_token_utils.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // Test: SimpleToken_utils.js 17 | // 18 | // http://www.simpletoken.org/ 19 | // 20 | // ---------------------------------------------------------------------------- 21 | 22 | const MockToken = artifacts.require('./MockToken.sol'); 23 | const config = require('../test_lib/config.js'); 24 | 25 | // / @dev Deploy 26 | module.exports.deployMockToken = async (artifacts, accounts) => { 27 | const token = await MockToken.new(config.decimals, { from: accounts[0], gas: 3500000 }); 28 | 29 | return { 30 | token, 31 | }; 32 | }; 33 | -------------------------------------------------------------------------------- /test/gateway/ost_composer/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const OSTComposer = artifacts.require('OSTComposer'); 22 | 23 | contract('OSTComposer.constructor() ', (accounts) => { 24 | let organization; 25 | let ostComposer; 26 | 27 | beforeEach(async () => { 28 | organization = accounts[4]; 29 | }); 30 | 31 | it('should able to deploy contract successfully', async () => { 32 | ostComposer = await OSTComposer.new(organization); 33 | 34 | assert( 35 | web3.utils.isAddress(ostComposer.address), 36 | 'Returned value is not a valid address.', 37 | ); 38 | }); 39 | 40 | it('should deploy with correct organization address', async () => { 41 | ostComposer = await OSTComposer.new(organization); 42 | 43 | assert.strictEqual( 44 | await ostComposer.organization(), 45 | organization, 46 | 'Incorrect organization is set', 47 | ); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /test/gateway/ost_composer/destruct_staker_proxy.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const OSTComposer = artifacts.require('TestOSTComposer'); 22 | const MockOrganization = artifacts.require('MockOrganization'); 23 | const StakerProxy = artifacts.require('MockStakerProxy'); 24 | const Utils = require('../../test_lib/utils'); 25 | 26 | contract('OSTComposer.destructStakerProxy() ', (accounts) => { 27 | let organization; 28 | let ostComposer; 29 | const stakeRequest = {}; 30 | let stakerProxy; 31 | let owner; 32 | let worker; 33 | beforeEach(async () => { 34 | owner = accounts[6]; 35 | worker = accounts[7]; 36 | organization = await MockOrganization.new(owner, worker); 37 | stakeRequest.staker = accounts[2]; 38 | ostComposer = await OSTComposer.new(organization.address); 39 | stakerProxy = await StakerProxy.new(); 40 | await ostComposer.setStakerProxy(stakeRequest.staker, stakerProxy.address); 41 | }); 42 | 43 | it('should be able to successfully remove staker proxy', async () => { 44 | const response = await ostComposer.destructStakerProxy( 45 | { from: stakeRequest.staker }, 46 | ); 47 | 48 | assert.strictEqual(response.receipt.status, true, 'Receipt status is unsuccessful'); 49 | 50 | const stakerProxyAddress = await ostComposer.stakerProxies.call(stakeRequest.staker); 51 | assert.strictEqual( 52 | stakerProxyAddress, 53 | Utils.NULL_ADDRESS, 54 | 'Staker\'s proxy address must be reset to null', 55 | ); 56 | 57 | const isSelfDestructed = await stakerProxy.selfDestruted.call(); 58 | assert.strictEqual( 59 | isSelfDestructed, 60 | true, 61 | 'Staker proxy self destruct must be called', 62 | ); 63 | }); 64 | 65 | it('should fail when owner doesn\'t have any deployed staker proxy', async () => { 66 | const nonProxy = accounts[8]; 67 | await Utils.expectRevert( 68 | ostComposer.destructStakerProxy( 69 | { from: nonProxy }, 70 | ), 71 | 'Staker proxy does not exist for the caller.', 72 | ); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/gateway/redeem_proxy/constructor.js: -------------------------------------------------------------------------------- 1 | const RedeemerProxy = artifacts.require('RedeemerProxy'); 2 | 3 | contract('RedeemerProxy.constructor()', (accounts) => { 4 | it('should construct successfully', async () => { 5 | const redeemPool = accounts[1]; 6 | const owner = accounts[2]; 7 | const proxy = await RedeemerProxy.new(owner, { from: redeemPool }); 8 | 9 | const actualComposer = await proxy.redeemPool.call(); 10 | const actualOwner = await proxy.owner.call(); 11 | 12 | assert.strictEqual( 13 | actualComposer, 14 | redeemPool, 15 | 'Redeem Pool address must match', 16 | ); 17 | 18 | assert.strictEqual( 19 | actualOwner, 20 | owner, 21 | 'Owner address must match', 22 | ); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/gateway/redeem_proxy/self_destruct.js: -------------------------------------------------------------------------------- 1 | const RedeemerProxy = artifacts.require('RedeemerProxy'); 2 | 3 | const web3 = require('../../test_lib/web3'); 4 | const Utils = require('../../test_lib/utils'); 5 | 6 | contract('RedeemerProxy.selfDestruct()', (accounts) => { 7 | let redeemPool; 8 | let owner; 9 | let proxy; 10 | 11 | beforeEach(async () => { 12 | redeemPool = accounts[1]; 13 | owner = accounts[2]; 14 | proxy = await RedeemerProxy.new(owner, { from: redeemPool }); 15 | }); 16 | 17 | it('should successfully self destruct', async () => { 18 | const codeBeforeSelfDestruct = await web3.eth.getCode(proxy.address); 19 | 20 | await proxy.selfDestruct({ from: redeemPool }); 21 | 22 | const codeAfterSelfDestruct = await web3.eth.getCode(proxy.address); 23 | 24 | assert.strictEqual( 25 | codeAfterSelfDestruct, 26 | '0x', 27 | 'Contract must be self destructed', 28 | ); 29 | 30 | assert.strictEqual( 31 | codeBeforeSelfDestruct.length > 2, 32 | true, 33 | `Contract must have deployed byte code but found ${codeBeforeSelfDestruct}`, 34 | ); 35 | }); 36 | 37 | it('should fail to self destruct for non redeemPool address', async () => { 38 | const nonComposerAddress = accounts[6]; 39 | await Utils.expectRevert( 40 | proxy.selfDestruct({ from: nonComposerAddress }), 41 | 'This function can only be called by the Redeem Pool.', 42 | ); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /test/gateway/redeem_proxy/transfer_token.js: -------------------------------------------------------------------------------- 1 | const RedeemerProxy = artifacts.require('RedeemerProxy'); 2 | const SpyToken = artifacts.require('SpyToken'); 3 | 4 | const BN = require('bn.js'); 5 | const Utils = require('../../test_lib/utils'); 6 | 7 | contract('RedeemerProxy.transferToken()', (accounts) => { 8 | let composer; 9 | let owner; 10 | let proxy; 11 | let token; 12 | const beneficiary = accounts[3]; 13 | const amount = new BN('100'); 14 | 15 | beforeEach(async () => { 16 | composer = accounts[1]; 17 | owner = accounts[2]; 18 | proxy = await RedeemerProxy.new(owner, { from: composer }); 19 | token = await SpyToken.new(); 20 | }); 21 | 22 | it('should successfully transfer token', async () => { 23 | await proxy.transferToken(token.address, beneficiary, amount, { from: owner }); 24 | 25 | const toAddress = await token.toAddress.call(); 26 | const transferAmount = await token.transferAmount.call(); 27 | 28 | assert.strictEqual( 29 | toAddress, 30 | beneficiary, 31 | 'To address must match', 32 | ); 33 | 34 | assert.strictEqual( 35 | amount.eq(new BN(transferAmount)), 36 | true, 37 | `Transfer amount should be ${amount} instead of ${transferAmount}`, 38 | ); 39 | }); 40 | 41 | it('should fail to transferToken for non owner address', async () => { 42 | const nonOwnerAddress = accounts[6]; 43 | await Utils.expectRevert( 44 | proxy.transferToken(token.address, beneficiary, amount, { from: nonOwnerAddress }), 45 | 'This function can only be called by the owner.', 46 | ); 47 | }); 48 | 49 | it('should fail if EIP20 transfer fails', async () => { 50 | await token.setTransferFakeResponse(false); 51 | await Utils.expectRevert( 52 | proxy.transferToken(token.address, beneficiary, amount, { from: owner }), 53 | 'EIP20Token transfer returned false.', 54 | ); 55 | }); 56 | 57 | it('should fail for zero token address', async () => { 58 | await Utils.expectRevert( 59 | proxy.transferToken(Utils.NULL_ADDRESS, beneficiary, amount, { from: owner }), 60 | 'The token address must not be address zero.', 61 | ); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /test/gateway/simple_stake/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const SimpleStake = artifacts.require('./SimpleStake.sol'); 22 | const MockToken = artifacts.require('./MockToken.sol'); 23 | 24 | const web3 = require('../../../test/test_lib/web3.js'); 25 | const config = require('../../test_lib/config.js'); 26 | const Utils = require('../../../test/test_lib/utils.js'); 27 | 28 | const zeroAddress = Utils.NULL_ADDRESS; 29 | contract('SimpleStake.constructor()', (accounts) => { 30 | const gateway = accounts[4]; 31 | let mockToken; 32 | beforeEach(async () => { 33 | mockToken = await MockToken.new(config.decimals, { from: accounts[0] }); 34 | }); 35 | 36 | it('should pass with correct parameters', async () => { 37 | const simpleStake = await SimpleStake.new(mockToken.address, gateway, { 38 | from: accounts[0], 39 | }); 40 | 41 | assert.strictEqual( 42 | web3.utils.isAddress(simpleStake.address), 43 | true, 44 | 'Returned value is not a valid address.', 45 | ); 46 | 47 | const valueToken = await simpleStake.valueToken.call(); 48 | // token supports previous ABIs 49 | const token = await simpleStake.token.call(); 50 | const actualGateway = await simpleStake.gateway.call(); 51 | 52 | assert.strictEqual( 53 | valueToken, 54 | mockToken.address, 55 | 'Expected token address is different from actual address.', 56 | ); 57 | assert.strictEqual( 58 | token, 59 | mockToken.address, 60 | 'Expected token address is different from actual address.', 61 | ); 62 | assert.strictEqual( 63 | gateway, 64 | actualGateway, 65 | 'Expected gateway address is different from actual address.', 66 | ); 67 | }); 68 | 69 | it('should fail if zero token address is passed', async () => { 70 | await Utils.expectRevert( 71 | SimpleStake.new(zeroAddress, gateway, { from: accounts[0] }), 72 | 'Value token contract address must not be zero.', 73 | ); 74 | }); 75 | 76 | it('should fail if zero gateway address is passed', async () => { 77 | await Utils.expectRevert( 78 | SimpleStake.new(mockToken.address, zeroAddress, { from: accounts[0] }), 79 | 'Gateway contract address must not be zero.', 80 | ); 81 | }); 82 | }); 83 | -------------------------------------------------------------------------------- /test/gateway/staker_proxy/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | 'use strict'; 22 | 23 | const StakerProxy = artifacts.require('./StakerProxy.sol'); 24 | const web3 = require('../../../test/test_lib/web3.js'); 25 | 26 | contract('StakerProxy.constructor()', (accounts) => { 27 | it('should pass with correct parameters', async () => { 28 | const [deployer, owner] = accounts; 29 | const stakerProxy = await StakerProxy.new( 30 | owner, 31 | { from: deployer }, 32 | ); 33 | 34 | assert.strictEqual( 35 | web3.utils.isAddress(stakerProxy.address), 36 | true, 37 | 'Deployed staker proxy contract does not have a valid contract address.', 38 | ); 39 | 40 | const composer = await stakerProxy.composer.call(); 41 | const ownerFromContract = await stakerProxy.owner.call(); 42 | 43 | assert.strictEqual( 44 | composer, 45 | deployer, 46 | 'Expected composer address is different from the actual address.', 47 | ); 48 | assert.strictEqual( 49 | ownerFromContract, 50 | owner, 51 | 'Expected owner address is different from the actual address.', 52 | ); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /test/gateway/staker_proxy/self_destruct.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | 'use strict'; 22 | 23 | const StakerProxy = artifacts.require('./StakerProxy.sol'); 24 | const Utils = require('../../test_lib/utils'); 25 | 26 | contract('StakerProxy.selfDestruct()', (accounts) => { 27 | const [composer, owner, anyOtherAddress] = accounts; 28 | let stakerProxy; 29 | 30 | beforeEach(async () => { 31 | stakerProxy = await StakerProxy.new( 32 | owner, 33 | { from: composer }, 34 | ); 35 | }); 36 | 37 | it('should allow self destruct by composer ', async () => { 38 | const response = await stakerProxy.selfDestruct({ from: composer }); 39 | 40 | assert.strictEqual(response.receipt.status, true, 'Receipt status is unsuccessful'); 41 | 42 | const stakerProxyCode = await web3.eth.getCode(stakerProxy.address); 43 | 44 | assert.strictEqual( 45 | stakerProxyCode, 46 | '0x', 47 | 'Staker proxy contract code should be 0x after self destructing', 48 | ); 49 | }); 50 | 51 | it('should not allow self destruct by non composer address ', async () => { 52 | await Utils.expectRevert( 53 | stakerProxy.selfDestruct({ from: anyOtherAddress }), 54 | 'This function can only be called by the composer.', 55 | ); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /test/gateway/staker_proxy/transfer_token.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | 'use strict'; 22 | 23 | const MockToken = artifacts.require('./MockToken.sol'); 24 | const StakerProxy = artifacts.require('./StakerProxy.sol'); 25 | const config = require('../../test_lib/config'); 26 | const Utils = require('../../test_lib/utils'); 27 | 28 | contract('StakerProxy.transferToken()', (accounts) => { 29 | const [deployer, owner, someoneElse] = accounts; 30 | const transferValue = '1000'; 31 | 32 | let stakerProxy; 33 | 34 | beforeEach(async () => { 35 | // Account deployer works, as no composer is queried for `transferToken`. 36 | stakerProxy = await StakerProxy.new( 37 | owner, 38 | { from: deployer }, 39 | ); 40 | }); 41 | 42 | it('should send the tokens to the desired recipient', async () => { 43 | const mockToken = await MockToken.new(config.decimals, { from: deployer }); 44 | await mockToken.transfer( 45 | stakerProxy.address, 46 | transferValue, 47 | { from: deployer }, 48 | ); 49 | 50 | await stakerProxy.transferToken( 51 | mockToken.address, 52 | someoneElse, 53 | transferValue, 54 | { from: owner }, 55 | ); 56 | 57 | const balance = await mockToken.balanceOf.call(someoneElse); 58 | 59 | assert.strictEqual( 60 | balance.toString(10), 61 | transferValue, 62 | 'The balance of `someoneElse` should equal the transfer value after the transfer.', 63 | ); 64 | }); 65 | 66 | it('should fail if not called by the owner', async () => { 67 | // Other function arguments are only placeholders as the call will fail on the modifier. 68 | await Utils.expectRevert( 69 | stakerProxy.transferToken( 70 | someoneElse, 71 | someoneElse, 72 | transferValue, 73 | { from: someoneElse }, 74 | ), 75 | 'This function can only be called by the owner.', 76 | ); 77 | }); 78 | 79 | it('should fail if attempting to transfer at token address zero.', async () => { 80 | // Other function arguments are only placeholders as the call will fail on first require. 81 | await Utils.expectRevert( 82 | stakerProxy.transferToken( 83 | Utils.NULL_ADDRESS, 84 | someoneElse, 85 | transferValue, 86 | { from: owner }, 87 | ), 88 | 'The token address may not be address zero.', 89 | ); 90 | }); 91 | }); 92 | -------------------------------------------------------------------------------- /test/lib/circular_buffer_uint/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const Utils = require('../../test_lib/utils.js'); 23 | 24 | const CircularBufferUint = artifacts.require('CircularBufferUint'); 25 | 26 | contract('CircularBufferUint.constructor()', async (accounts) => { 27 | it('deploys given accepted arguments', async () => { 28 | await CircularBufferUint.new(new BN(100)); 29 | }); 30 | 31 | it('reverts if the given buffer length is 0', async () => { 32 | await Utils.expectRevert( 33 | CircularBufferUint.new(new BN(0)), 34 | 'The max number of items to store in a circular buffer must be greater than 0.', 35 | ); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /test/lib/circular_buffer_uint/store.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | 23 | const CircularBufferUint = artifacts.require('TestCircularBufferUint'); 24 | 25 | contract('CircularBufferUint.store()', async (accounts) => { 26 | it('stores the given number of max items', async () => { 27 | /* 28 | * The first ten items are `0`, because that is the buffer length and 29 | * in the loop it will check for data at a lower index than was written. 30 | */ 31 | const data = [ 32 | new BN(0), 33 | new BN(0), 34 | new BN(0), 35 | new BN(0), 36 | new BN(0), 37 | new BN(0), 38 | new BN(0), 39 | new BN(0), 40 | new BN(0), 41 | new BN(0), 42 | new BN(1), 43 | new BN(2), 44 | new BN(3), 45 | new BN(4), 46 | new BN(5), 47 | new BN(6), 48 | new BN(7), 49 | new BN(8), 50 | new BN(9), 51 | new BN(10), 52 | new BN(11), 53 | new BN(12), 54 | new BN(13), 55 | new BN(14), 56 | new BN(15), 57 | new BN(16), 58 | new BN(17), 59 | new BN(18), 60 | new BN(19), 61 | new BN(20), 62 | ]; 63 | 64 | /* 65 | * Buffer length is less than the length of the array of test data. This 66 | * means, that by iterating over all test data, the buffer will start 67 | * overwriting old values. In the loop, it checks that the buffer 68 | * returns the correct overwritten value. 69 | */ 70 | const bufferLength = 10; 71 | const buffer = await CircularBufferUint.new(new BN(bufferLength)); 72 | 73 | /* 74 | * Start at `i = bufferLength` to be able to query for test data at a 75 | * lower index. 76 | */ 77 | const count = data.length; 78 | for (let i = bufferLength; i < count; i++) { 79 | const previousItem = await buffer.storeExternal.call(data[i]); 80 | const expectedPreviousItem = data[i - bufferLength]; 81 | assert( 82 | previousItem.eq(expectedPreviousItem), 83 | 'The contract did not return the expected item that should ' 84 | + 'have been overwritten.', 85 | ); 86 | 87 | await buffer.storeExternal(data[i]); 88 | const head = await buffer.headExternal.call(); 89 | const expectedHead = data[i]; 90 | assert( 91 | head.eq(expectedHead), 92 | 'The contract did not update the head to the latest stored item.', 93 | ); 94 | } 95 | }); 96 | }); 97 | -------------------------------------------------------------------------------- /test/lib/gatewaylib/hash_redeem_intent.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const GatewayLib = artifacts.require('GatewayLib'); 22 | 23 | const BN = require('bn.js'); 24 | const Utils = require('../../gateway/eip20_cogateway/helpers/co_gateway_utils'); 25 | 26 | contract('GatewayLib.hashRedeemIntent()', async (accounts) => { 27 | it('should return correct redeem intent hash', async () => { 28 | const gatewayLib = await GatewayLib.deployed(); 29 | const amount = new BN(1); 30 | const beneficiary = accounts[0]; 31 | const gateway = accounts[1]; 32 | 33 | const redeemIntentHash = await gatewayLib.hashRedeemIntent( 34 | amount, 35 | beneficiary, 36 | gateway, 37 | ); 38 | 39 | const expectedRedeemIntentHash = Utils.hashRedeemIntent( 40 | amount, 41 | beneficiary, 42 | gateway, 43 | ); 44 | 45 | assert.strictEqual( 46 | expectedRedeemIntentHash, 47 | redeemIntentHash, 48 | 'The library did not hash the redeem intent as expected.', 49 | ); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /test/lib/gatewaylib/hash_stake_intent.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const GatewayLib = artifacts.require('GatewayLib'); 22 | 23 | const BN = require('bn.js'); 24 | const Utils = require('../../gateway/eip20_cogateway/helpers/co_gateway_utils'); 25 | 26 | contract('GatewayLib.hashStakeIntent()', async (accounts) => { 27 | it('should return correct stake intent hash', async () => { 28 | const gatewayLib = await GatewayLib.deployed(); 29 | const amount = new BN(1); 30 | const beneficiary = accounts[0]; 31 | const gateway = accounts[1]; 32 | 33 | const stakeIntentHash = await gatewayLib.hashStakeIntent( 34 | amount, 35 | beneficiary, 36 | gateway, 37 | ); 38 | 39 | const expectedStakeIntentHash = Utils.hashStakeIntent( 40 | amount, 41 | beneficiary, 42 | gateway, 43 | ); 44 | 45 | assert.strictEqual( 46 | expectedStakeIntentHash, 47 | stakeIntentHash, 48 | 'The library did not hash the stake intent as expected.', 49 | ); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /test/lib/messagebus/confirm_message.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | // 21 | const MessageBusUtils = require('./messagebus_utils'); 22 | 23 | contract('MessageBus.confirmMessage()', async (accounts) => { 24 | let params; 25 | 26 | beforeEach(async () => { 27 | await MessageBusUtils.deployedMessageBus(); 28 | params = MessageBusUtils.defaultParams(accounts); 29 | }); 30 | 31 | it('should fail when message status is declared ', async () => { 32 | const message = 'Message on target must be Undeclared.'; 33 | params.message = message; 34 | 35 | await MessageBusUtils.confirmMessage(params, true); 36 | 37 | await MessageBusUtils.confirmMessage(params, false); 38 | }); 39 | 40 | it('should fail when message status is progressed ', async () => { 41 | const message = 'Message on target must be Undeclared.'; 42 | params.message = message; 43 | 44 | await MessageBusUtils.confirmMessage(params, true); 45 | await MessageBusUtils.progressInbox(params, true); 46 | 47 | await MessageBusUtils.confirmMessage(params, false); 48 | }); 49 | 50 | it('should fail when message status is revoked ', async () => { 51 | const message = 'Message on target must be Undeclared.'; 52 | params.message = message; 53 | await MessageBusUtils.confirmMessage(params, true); 54 | await MessageBusUtils.confirmRevocation(params, true); 55 | 56 | await MessageBusUtils.confirmMessage(params, false); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /test/lib/messagebus/confirm_revocation.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const MessageBusUtils = require('./messagebus_utils'); 22 | 23 | contract('MessageBus.confirmRevocation()', async (accounts) => { 24 | let params; 25 | 26 | beforeEach(async () => { 27 | await MessageBusUtils.deployedMessageBus(); 28 | params = MessageBusUtils.defaultParams(accounts); 29 | }); 30 | 31 | it( 32 | 'should fail when message status of the message hash in inbox is' 33 | + ' undeclared ', 34 | async () => { 35 | const message = 'Message on target must be Declared.'; 36 | params.message = message; 37 | 38 | await MessageBusUtils.confirmRevocation(params, false); 39 | }, 40 | ); 41 | 42 | it( 43 | 'should fail when message status of the message hash in inbox is' 44 | + ' progressed ', 45 | async () => { 46 | const message = 'Message on target must be Declared.'; 47 | params.message = message; 48 | 49 | await MessageBusUtils.confirmMessage(params, true); 50 | await MessageBusUtils.progressInbox(params, true); 51 | 52 | await MessageBusUtils.confirmRevocation(params, false); 53 | }, 54 | ); 55 | 56 | it( 57 | 'should fail when message status of the message hash in inbox is' 58 | + ' revoked', 59 | async () => { 60 | const message = 'Message on target must be Declared.'; 61 | params.message = message; 62 | 63 | await MessageBusUtils.confirmMessage(params, true); 64 | await MessageBusUtils.confirmRevocation(params, true); 65 | 66 | await MessageBusUtils.confirmRevocation(params, false); 67 | }, 68 | ); 69 | }); 70 | -------------------------------------------------------------------------------- /test/lib/messagebus/declare_message.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const messageBus = require('../../test_lib/message_bus.js'); 22 | const MessageBusUtils = require('./messagebus_utils'); 23 | 24 | const { MessageStatusEnum } = messageBus; 25 | 26 | contract('MessageBus.declareMessage()', async (accounts) => { 27 | let params; 28 | 29 | beforeEach(async () => { 30 | await MessageBusUtils.deployedMessageBus(); 31 | 32 | params = MessageBusUtils.defaultParams(accounts); 33 | }); 34 | 35 | it('should fail when message status is already in declared state', async () => { 36 | const message = 'Message on source must be Undeclared.'; 37 | params.message = message; 38 | 39 | await MessageBusUtils.declareMessage(params, true); 40 | await MessageBusUtils.declareMessage(params, false); 41 | }); 42 | 43 | it('should fail when message status is progressed in outbox', async () => { 44 | const message = 'Message on source must be Undeclared.'; 45 | params.message = message; 46 | 47 | await MessageBusUtils.declareMessage(params, true); 48 | await MessageBusUtils.progressOutbox(params, true); 49 | 50 | await MessageBusUtils.declareMessage(params, false); 51 | }); 52 | 53 | it('should fail when message status is DeclaredRevocation in outbox', async () => { 54 | const message = 'Message on source must be Undeclared.'; 55 | params.message = message; 56 | 57 | await MessageBusUtils.declareMessage(params, true); 58 | await MessageBusUtils.declareRevocationMessage(params, true); 59 | 60 | await MessageBusUtils.declareMessage(params, false); 61 | }); 62 | 63 | it('should fail when message status is Revoked in outbox', async () => { 64 | const message = 'Message on source must be Undeclared.'; 65 | params.message = message; 66 | 67 | await MessageBusUtils.declareMessage(params, true); 68 | await MessageBusUtils.declareRevocationMessage(params, true); 69 | params.messageStatus = MessageStatusEnum.Revoked; 70 | await MessageBusUtils.progressOutboxRevocation(params, true); 71 | 72 | await MessageBusUtils.declareMessage(params, false); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/lib/messagebus/declare_revocation_message.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const MessageBusUtils = require('./messagebus_utils'); 22 | const messageBus = require('../../test_lib/message_bus.js'); 23 | 24 | const { MessageStatusEnum } = messageBus; 25 | 26 | contract('MessageBus.declareRevocationMessage()', async (accounts) => { 27 | let params; 28 | 29 | beforeEach(async () => { 30 | await MessageBusUtils.deployedMessageBus(); 31 | params = MessageBusUtils.defaultParams(accounts); 32 | }); 33 | 34 | it('should fail when message status is undeclared in outbox', async () => { 35 | const message = 'Message on source must be Declared.'; 36 | params.message = message; 37 | 38 | await MessageBusUtils.declareRevocationMessage(params, false); 39 | }); 40 | 41 | it('should fail when message status is Progressed in outbox', async () => { 42 | const message = 'Message on source must be Declared.'; 43 | params.message = message; 44 | 45 | await MessageBusUtils.declareMessage(params, true); 46 | await MessageBusUtils.progressOutbox(params, true); 47 | 48 | await MessageBusUtils.declareRevocationMessage(params, false); 49 | }); 50 | 51 | it('should fail when message status is DeclaredRevocation in outbox', async () => { 52 | const message = 'Message on source must be Declared.'; 53 | params.message = message; 54 | 55 | await MessageBusUtils.declareMessage(params, true); 56 | await MessageBusUtils.declareRevocationMessage(params, true); 57 | 58 | await MessageBusUtils.declareRevocationMessage(params, false); 59 | }); 60 | 61 | it('should fail when message status is Revoked in outbox', async () => { 62 | const message = 'Message on source must be Declared.'; 63 | params.message = message; 64 | 65 | await MessageBusUtils.declareMessage(params, true); 66 | await MessageBusUtils.declareRevocationMessage(params, true); 67 | params.messageStatus = MessageStatusEnum.Revoked; 68 | await MessageBusUtils.progressOutboxRevocation(params, true); 69 | 70 | await MessageBusUtils.declareRevocationMessage(params, false); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /test/lib/messagebus/progress_inbox.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const web3 = require('web3'); 22 | const MessageBusUtils = require('./messagebus_utils'); 23 | 24 | contract('MessageBus.progressInbox()', async (accounts) => { 25 | let params; 26 | 27 | beforeEach(async () => { 28 | await MessageBusUtils.deployedMessageBus(); 29 | params = MessageBusUtils.defaultParams(accounts); 30 | }); 31 | 32 | it('should fail when message status is undeclared in inbox', async () => { 33 | const message = 'Message on target status must be Declared.'; 34 | params.message = message; 35 | 36 | await MessageBusUtils.progressInbox(params, false); 37 | }); 38 | 39 | it('should fail when message status is already progressed in inbox', async () => { 40 | const message = 'Message on target status must be Declared.'; 41 | params.message = message; 42 | 43 | await MessageBusUtils.confirmMessage(params, true); 44 | await MessageBusUtils.progressInbox(params, true); 45 | 46 | await MessageBusUtils.progressInbox(params, false); 47 | }); 48 | 49 | it('should fail when message status is revoked in inbox', async () => { 50 | const message = 'Message on target status must be Declared.'; 51 | params.message = message; 52 | 53 | await MessageBusUtils.confirmMessage(params, true); 54 | await MessageBusUtils.confirmRevocation(params, true); 55 | 56 | await MessageBusUtils.progressInbox(params, false); 57 | }); 58 | 59 | it('should fail when unlock secret is incorrect', async () => { 60 | const message = 'Invalid unlock secret.'; 61 | params.message = message; 62 | 63 | await MessageBusUtils.confirmMessage(params, true); 64 | params.unlockSecret = web3.utils.soliditySha3({ 65 | type: 'bytes32', 66 | value: 'secret1', 67 | }); 68 | await MessageBusUtils.progressInbox(params, false); 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /test/lib/messagebus/progress_outbox.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const web3 = require('web3'); 22 | const MessageBusUtils = require('./messagebus_utils'); 23 | const messageBus = require('../../test_lib/message_bus.js'); 24 | 25 | const { MessageStatusEnum } = messageBus; 26 | contract('MessageBus.progressOutbox()', async (accounts) => { 27 | let params; 28 | 29 | beforeEach(async () => { 30 | await MessageBusUtils.deployedMessageBus(); 31 | params = MessageBusUtils.defaultParams(accounts); 32 | }); 33 | 34 | it('should fail when message status is undeclared in outbox', async () => { 35 | const message = 'Message on source must be Declared.'; 36 | params.message = message; 37 | 38 | await MessageBusUtils.progressOutbox(params, false); 39 | }); 40 | 41 | it('should fail when message status is already progressed in outbox', async () => { 42 | const message = 'Message on source must be Declared.'; 43 | params.message = message; 44 | 45 | await MessageBusUtils.declareMessage(params, true); 46 | await MessageBusUtils.progressOutbox(params, true); 47 | await MessageBusUtils.progressOutbox(params, false); 48 | }); 49 | 50 | it('should fail when message status is declared revocation in outbox', async () => { 51 | const message = 'Message on source must be Declared.'; 52 | params.message = message; 53 | 54 | await MessageBusUtils.declareMessage(params, true); 55 | await MessageBusUtils.declareRevocationMessage(params, true); 56 | await MessageBusUtils.progressOutbox(params, false); 57 | }); 58 | 59 | it('should fail when message status is revoked in outbox', async () => { 60 | const message = 'Message on source must be Declared.'; 61 | params.message = message; 62 | 63 | await MessageBusUtils.declareMessage(params, true); 64 | await MessageBusUtils.declareRevocationMessage(params, true); 65 | params.messageStatus = MessageStatusEnum.Revoked; 66 | await MessageBusUtils.progressOutboxRevocation(params, true); 67 | await MessageBusUtils.progressOutbox(params, false); 68 | }); 69 | 70 | it('should fail when unlock secret is incorrect', async () => { 71 | const message = 'Invalid unlock secret.'; 72 | params.message = message; 73 | 74 | params.unlockSecret = web3.utils.soliditySha3({ 75 | type: 'bytes32', 76 | value: 'secret1', 77 | }); 78 | await MessageBusUtils.progressOutbox(params, false); 79 | }); 80 | }); 81 | -------------------------------------------------------------------------------- /test/lib/organization/is_organization.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | const BN = require('bn.js'); 16 | const web3 = require('../../test_lib/web3.js'); 17 | const Utils = require('../../test_lib/utils.js'); 18 | 19 | const Organization = artifacts.require('Organization'); 20 | 21 | contract('Organization.isOrganization()', async (accounts) => { 22 | const owner = accounts[0]; 23 | const admin = accounts[1]; 24 | const worker = accounts[2]; 25 | let organization = null; 26 | 27 | beforeEach(async () => { 28 | const zeroAdmin = Utils.NULL_ADDRESS; 29 | const workers = []; 30 | const expirationHeight = 0; 31 | 32 | organization = await Organization.new( 33 | owner, 34 | zeroAdmin, 35 | workers, 36 | expirationHeight, 37 | ); 38 | }); 39 | 40 | it('should return the owner as the organization', async () => { 41 | const isOrganization = await organization.isOrganization(owner); 42 | 43 | assert.strictEqual( 44 | isOrganization, 45 | true, 46 | 'The owner should be recognized as organization.', 47 | ); 48 | }); 49 | 50 | it('should return the admin as the organization', async () => { 51 | await organization.setAdmin(admin, { from: owner }); 52 | const isOrganization = await organization.isOrganization(admin); 53 | 54 | assert.strictEqual( 55 | isOrganization, 56 | true, 57 | 'The admin should be recognized as organization.', 58 | ); 59 | }); 60 | 61 | it('should not return a worker as the organization', async () => { 62 | const currentBlockHeight = await web3.eth.getBlockNumber(); 63 | const expirationHeight = currentBlockHeight + 1000; 64 | await organization.setWorker(worker, new BN(expirationHeight), { 65 | from: owner, 66 | }); 67 | const isOrganization = await organization.isOrganization(admin); 68 | 69 | assert.strictEqual( 70 | isOrganization, 71 | false, 72 | 'A worker should not be recognized as organization.', 73 | ); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/lib/organization/unset_worker.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const web3 = require('../../test_lib/web3.js'); 22 | 23 | const Utils = require('../../test_lib/utils.js'); 24 | const EventsDecoder = require('../../test_lib/event_decoder.js'); 25 | 26 | const Organization = artifacts.require('Organization'); 27 | 28 | contract('Organization.unsetWorker()', async (accounts) => { 29 | const owner = accounts[0]; 30 | const worker = accounts[1]; 31 | const admin = accounts[2]; 32 | 33 | let organization = null; 34 | let expirationHeight; 35 | 36 | beforeEach(async () => { 37 | expirationHeight = (await web3.eth.getBlockNumber()) + 10; 38 | 39 | const zeroAdmin = Utils.NULL_ADDRESS; 40 | const workers = []; 41 | organization = await Organization.new( 42 | owner, 43 | zeroAdmin, 44 | workers, 45 | expirationHeight, 46 | ); 47 | await organization.setWorker(worker, expirationHeight, { from: owner }); 48 | }); 49 | 50 | it('reverts when caller is not owner/admin', async () => { 51 | await Utils.expectRevert( 52 | organization.unsetWorker(worker, { from: accounts[4] }), 53 | 'Only owner and admin are allowed to call this method.', 54 | ); 55 | }); 56 | 57 | it('should pass when owner unsets/deactivates a worker', async () => { 58 | await organization.unsetWorker(worker, { from: owner }); 59 | 60 | const returnedWorker = await organization.workers.call(worker); 61 | assert(returnedWorker.eqn(0), 'Worker should be reset to zero.'); 62 | }); 63 | 64 | it('should pass when admin unsets/deactivates a worker', async () => { 65 | await organization.setAdmin(admin, { from: owner }); 66 | await organization.unsetWorker(worker, { from: admin }); 67 | 68 | const returnedWorker = await organization.workers.call(worker); 69 | assert(returnedWorker.eqn(0), 'Worker should be reset to zero.'); 70 | }); 71 | 72 | it('emits an unsetWorker event when worker is present', async () => { 73 | await organization.setWorker(worker, expirationHeight, { from: owner }); 74 | const transaction = await organization.unsetWorker(worker, { 75 | from: owner, 76 | }); 77 | const events = EventsDecoder.getEvents(transaction, organization); 78 | 79 | assert.strictEqual( 80 | events.WorkerUnset.worker, 81 | worker, 82 | 'The event should list the worker that was unset.', 83 | ); 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /test/lib/organized/constructor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const Utils = require('../../test_lib/utils.js'); 22 | 23 | const Organization = artifacts.require('Organization'); 24 | const Organized = artifacts.require('Organized'); 25 | 26 | contract('Organized.constructor()', async (accounts) => { 27 | const owner = accounts[0]; 28 | let organization = null; 29 | 30 | beforeEach(async () => { 31 | const admin = Utils.NULL_ADDRESS; 32 | const workers = []; 33 | const expirationHeight = 0; 34 | 35 | organization = await Organization.new( 36 | owner, 37 | admin, 38 | workers, 39 | expirationHeight, 40 | ); 41 | }); 42 | 43 | it('reverts when organization address is null', async () => { 44 | await Utils.expectRevert( 45 | Organized.new(Utils.NULL_ADDRESS, { from: owner }), 46 | 'Organization contract address must not be zero.', 47 | ); 48 | }); 49 | 50 | it('checks that valid organization address is set', async () => { 51 | const organized = await Organized.new(organization.address, { 52 | from: owner, 53 | }); 54 | assert.strictEqual( 55 | await organized.organization.call(), 56 | organization.address, 57 | 'The organized contract should store the given organization.', 58 | ); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /test/lib/safe_math.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // Utility chain: OpenSTUtility 17 | // 18 | // http://www.simpletoken.org/ 19 | // 20 | // Based on the SafeMath library by the OpenZeppelin team. 21 | // Copyright (c) 2016 Smart Contract Solutions, Inc. 22 | // https://github.com/OpenZeppelin/zeppelin-solidity 23 | // The MIT License. 24 | // ---------------------------------------------------------------------------- 25 | 26 | const BN = require('bn.js'); 27 | const Utils = require('../test_lib/utils.js'); 28 | 29 | const TestSafeMath = artifacts.require('TestSafeMath'); 30 | 31 | contract('SafeMath', () => { 32 | let safeMath; 33 | 34 | before(async () => { 35 | safeMath = await TestSafeMath.new(); 36 | }); 37 | 38 | it('multiplies correctly', async () => { 39 | const a = 5678; 40 | const b = 1234; 41 | await safeMath.multiply(a, b); 42 | const result = await safeMath.result(); 43 | assert.equal(result, a * b); 44 | }); 45 | 46 | it('adds correctly', async () => { 47 | const a = 5678; 48 | const b = 1234; 49 | await safeMath.add(a, b); 50 | const result = await safeMath.result(); 51 | 52 | assert.equal(result, a + b); 53 | }); 54 | 55 | it('subtracts correctly', async () => { 56 | const a = 5678; 57 | const b = 1234; 58 | await safeMath.subtract(a, b); 59 | const result = await safeMath.result(); 60 | 61 | assert.equal(result, a - b); 62 | }); 63 | 64 | it('should throw an error if subtraction result would be negative', async () => { 65 | const a = 1234; 66 | const b = 5678; 67 | await Utils.expectThrow(safeMath.subtract(a, b)); 68 | }); 69 | 70 | it('should throw an error on addition overflow', async () => { 71 | const a = new BN( 72 | '115792089237316195423570985008687907853269984665640564039457584007913129639935', 73 | ); 74 | const b = new BN(1); 75 | await Utils.expectThrow(safeMath.add(a, b)); 76 | }); 77 | 78 | it('should throw an error on multiplication overflow', async () => { 79 | const a = new BN( 80 | '115792089237316195423570985008687907853269984665640564039457584007913129639933', 81 | ); 82 | const b = new BN(2); 83 | await Utils.expectThrow(safeMath.multiply(a, b)); 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /test/test_lib/config.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | 'use strict'; 22 | 23 | /* eslint-disable @typescript-eslint/no-var-requires */ 24 | const { env } = require('process'); 25 | 26 | /** Test wide configuration for various tests. */ 27 | const config = { 28 | /** Defaults to 18. Can be overriden with the environment variable OPENST_DECIMALS. */ 29 | get decimals() { 30 | let decimals = 18; 31 | 32 | if (env.OPENST_DECIMALS) { 33 | decimals = Number.parseInt(env.OPENST_DECIMALS, 10); 34 | } 35 | 36 | return decimals; 37 | }, 38 | }; 39 | 40 | module.exports = config; 41 | -------------------------------------------------------------------------------- /test/test_lib/hash_lock.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // Test: lib/hash_lock.js 17 | // 18 | // http://www.simpletoken.org/ 19 | // 20 | // ---------------------------------------------------------------------------- 21 | 22 | const crypto = require('crypto'); 23 | 24 | const keccak256 = require('keccak'); 25 | 26 | // / for testing purposes produce a random secret and its hash 27 | module.exports.getHashLock = () => { 28 | // NOTE: for openst-platform encrypt secret 29 | const secretBytes = crypto.randomBytes(32); 30 | const lock = `0x${keccak256('keccak256') 31 | .update(secretBytes) 32 | .digest('hex')}`; 33 | const unlockSecret = `0x${secretBytes.toString('hex')}`; 34 | return { s: unlockSecret, l: lock }; 35 | }; 36 | -------------------------------------------------------------------------------- /test/test_lib/message_bus.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const web3 = require('./web3.js'); 22 | const utils = require('./utils.js'); 23 | 24 | const messageTypeHash = utils.getTypeHash( 25 | 'Message(bytes32 intentHash,uint256 nonce,uint256 gasPrice,uint256 gasLimit,address sender,bytes32 hashLock)', 26 | ); 27 | 28 | function MessageBus() {} 29 | 30 | MessageBus.prototype = { 31 | /** 32 | * Creates an EIP-712 conform hash of the message that is equal to the hash 33 | * generated in solidity. 34 | * 35 | * @param {string} intentHash The hash of the intent, e.g. stake or redeem. 36 | * @param {BN} nonce The nonce of the sender. 37 | * @param {BN} gasPrice The price per gas to pay for relaying the message. 38 | * @param {BN} gasLimit The max gas to pay for relaying the message. 39 | * @param {string} sender The sender (creator) of this message. 40 | * @param {string} hashLock A hashed secret to progress the message. 41 | * 42 | * @returns The hash of the given parameters, according to the specification 43 | * of a message hash. 44 | */ 45 | messageDigest: (intentHash, nonce, gasPrice, gasLimit, sender, hashLock) => { 46 | const digest = web3.utils.sha3( 47 | web3.eth.abi.encodeParameters( 48 | [ 49 | 'bytes32', 50 | 'bytes32', 51 | 'uint256', 52 | 'uint256', 53 | 'uint256', 54 | 'address', 55 | 'bytes32', 56 | ], 57 | [ 58 | messageTypeHash, 59 | intentHash, 60 | nonce.toNumber(), 61 | gasPrice.toNumber(), 62 | gasLimit.toNumber(), 63 | sender, 64 | hashLock, 65 | ], 66 | ), 67 | ); 68 | 69 | return digest; 70 | }, 71 | 72 | MessageStatusEnum: { 73 | Undeclared: 0, 74 | Declared: 1, 75 | Progressed: 2, 76 | DeclaredRevocation: 3, 77 | Revoked: 4, 78 | }, 79 | }; 80 | 81 | module.exports = new MessageBus(); 82 | -------------------------------------------------------------------------------- /test/test_lib/web3.js: -------------------------------------------------------------------------------- 1 | const Web3 = require('web3'); 2 | 3 | const web3 = new Web3(Web3.givenProvider || 'http://localhost:8545'); 4 | 5 | module.exports = web3; 6 | -------------------------------------------------------------------------------- /test_integration/03_redeem_and_unstake/utils/confirm_revert_redeem_intent_assertion.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const assert = require('assert'); 22 | 23 | /** 24 | * Redeem Request object contains all the properties for redeem and unstake. 25 | * @typedef {Object} RedeemRequest 26 | * @property {BN} amount Redeem amount. 27 | * @property {BN} gasPrice Gas price that Redeemer is ready to pay to get the 28 | * redeem and unstake process done. 29 | * @property {BN} gasLimit Gas limit that redeemer is ready to pay. 30 | * @property {string} redeemer Address of Redeemer. 31 | * @property {BN} bounty Bounty amount paid for redeem and unstake message 32 | * transfers. 33 | * @property {BN} nonce Redeem nonce. 34 | * @property {string} beneficiary Address of beneficiary on origin chain. 35 | * @property {string} hashLock Hash Lock provided by the redeemer. 36 | * @property {string} unlockSecret Unlock secret to unlock hash lock. 37 | * @property {string} messageHash Identifier for redeem and unstake process. 38 | * @property {BN} blockHeight Height at which anchor state root is done. 39 | */ 40 | 41 | /** 42 | * Class to assert confirm revert redeem intent. 43 | */ 44 | class ConfirmRevertRedeemIntentAssertion { 45 | /** 46 | * This verifies event. 47 | * @param {Object} event Event object after decoding. 48 | * @param {RedeemRequest} redeemRequest Redeem request parameters. 49 | */ 50 | static verify(event, redeemRequest) { 51 | const eventData = event.RevertRedeemIntentConfirmed; 52 | 53 | assert.strictEqual( 54 | eventData._messageHash, 55 | redeemRequest.messageHash, 56 | `Message hash from event must be equal to ${redeemRequest.messageHash}.`, 57 | ); 58 | 59 | assert.strictEqual( 60 | eventData._redeemer, 61 | redeemRequest.redeemer, 62 | `Redeemer address from event must be equal to ${redeemRequest.redeemer}.`, 63 | ); 64 | 65 | assert.strictEqual( 66 | redeemRequest.nonce.eq(eventData._redeemerNonce), 67 | true, 68 | `Redeem nonce from event must be equal to ${redeemRequest.nonce.toString(10)}.`, 69 | ); 70 | 71 | assert.strictEqual( 72 | redeemRequest.amount.eq(eventData._amount), 73 | true, 74 | `Amount from event must be equal to ${redeemRequest.amount.toString(10)}.`, 75 | ); 76 | } 77 | } 78 | 79 | module.exports = ConfirmRevertRedeemIntentAssertion; 80 | -------------------------------------------------------------------------------- /test_integration/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | 5 | geth_node_origin: 6 | image: augurproject/dev-node-geth:v1.8.18 7 | ports: 8 | - "8546:8545" 9 | 10 | geth_node_auxiliary: 11 | image: augurproject/dev-node-geth:v1.8.18 12 | ports: 13 | - "8547:8545" 14 | -------------------------------------------------------------------------------- /test_integration/docker.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const waitPort = require('wait-port'); 22 | 23 | const originPort = 8546; 24 | const auxiliaryPort = 8547; 25 | 26 | const asyncSleep = ms => new Promise(resolve => setTimeout(resolve, ms)); 27 | 28 | const docker = () => { 29 | const waitForOriginNode = waitPort({ port: originPort, output: 'silent' }); 30 | const waitForAuxiliaryNode = waitPort({ port: auxiliaryPort, output: 'silent' }); 31 | return Promise.all([waitForOriginNode, waitForAuxiliaryNode]).then( 32 | // even after the ports are available the nodes need a bit of time to get online 33 | () => asyncSleep(5000), 34 | ).then(() => ({ 35 | rpcEndpointOrigin: `http://localhost:${originPort}`, 36 | rpcEndpointAuxiliary: `http://localhost:${auxiliaryPort}`, 37 | })); 38 | }; 39 | 40 | module.exports = docker; 41 | -------------------------------------------------------------------------------- /test_integration/integration_tests.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | /** 22 | * @file Truffle's `artifacts.require()` won't be available inside the Mocha 23 | * tests. Thus, we load them here and add them to the `shared` object. 24 | */ 25 | const Mocha = require('mocha'); 26 | const shared = require('./shared'); 27 | 28 | const Anchor = artifacts.require('Anchor'); 29 | const EIP20Gateway = artifacts.require('EIP20Gateway'); 30 | const EIP20CoGateway = artifacts.require('EIP20CoGateway'); 31 | const EIP20StandardToken = artifacts.require('EIP20StandardToken'); 32 | const OSTPrime = artifacts.require('OSTPrime'); 33 | const OSTComposer = artifacts.require('OSTComposer'); 34 | const RedeemPool = artifacts.require('RedeemPool'); 35 | 36 | const setupArtifacts = () => { 37 | shared.artifacts = { 38 | Anchor, 39 | EIP20Gateway, 40 | EIP20CoGateway, 41 | EIP20StandardToken, 42 | OSTPrime, 43 | OSTComposer, 44 | RedeemPool, 45 | }; 46 | }; 47 | 48 | const runTests = (callback) => { 49 | const mocha = new Mocha({ 50 | enableTimeouts: false, 51 | }); 52 | 53 | Mocha.utils.lookupFiles(__dirname, ['js'], true) 54 | .filter( 55 | // Skipping this file so that artifacts are not loaded. 56 | file => file !== __filename, 57 | ) 58 | .forEach((file) => { 59 | mocha.addFile(file); 60 | }); 61 | 62 | mocha.run((failures) => { 63 | callback(failures); 64 | }); 65 | }; 66 | 67 | module.exports = (callback) => { 68 | setupArtifacts(); 69 | runTests(callback); 70 | }; 71 | -------------------------------------------------------------------------------- /test_integration/lib/anchor.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const BN = require('bn.js'); 22 | const AnchorStateRootAssertion = require('./anchor_stateroot_assertion'); 23 | const EventDecoder = require('../../test/test_lib/event_decoder'); 24 | 25 | /** 26 | * This class represents anchor contract on a chain. 27 | */ 28 | class Anchor { 29 | /** 30 | * Constructor 31 | * @param {Web3} sourceWeb3 Web3 of source chain for which this anchor 32 | * tracks state root. 33 | * @param {Object} anchor Contract instance of anchor contract on target 34 | * chain. 35 | * @param {string} organization Organization address of the organization 36 | * that is responsible for anchoring the state root on 37 | * target chain. 38 | */ 39 | constructor(sourceWeb3, anchor, organization) { 40 | this.sourceWeb3 = sourceWeb3; 41 | this.anchor = anchor; 42 | this.organization = organization; 43 | } 44 | 45 | /** 46 | * This anchors a state root at a given block height. 47 | * @param {number | string} atBlock Block at which state root needs to 48 | * anchor. Default value is latest. 49 | * @return {Promise} Returns blockHeight at which state 50 | * root is anchored. 51 | */ 52 | async anchorStateRoot(atBlock = 'latest') { 53 | const block = await this.sourceWeb3.eth.getBlock(atBlock); 54 | const blockHeight = new BN(block.number); 55 | const { stateRoot } = block; 56 | const tx = await this.anchor.anchorStateRoot( 57 | blockHeight, 58 | stateRoot, 59 | { from: this.organization }, 60 | ); 61 | 62 | const event = EventDecoder.getEvents(tx, this.anchor); 63 | AnchorStateRootAssertion.verify( 64 | event, 65 | blockHeight, 66 | stateRoot, 67 | ); 68 | return block.number; 69 | } 70 | } 71 | 72 | module.exports = Anchor; 73 | -------------------------------------------------------------------------------- /test_integration/lib/anchor_stateroot_assertion.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const assert = require('assert'); 22 | 23 | /** 24 | * Class to assert anchor state root. 25 | */ 26 | class AnchorStateRootAssertion { 27 | /** 28 | * This asserts StateRootAvailable event. 29 | * @param {Object} event Deserialize event. 30 | * @param {Number} blockHeight Block Height at which state root is anchored. 31 | * @param {string} stateRoot State root which is anchored. 32 | */ 33 | static verify(event, blockHeight, stateRoot) { 34 | const eventData = event.StateRootAvailable; 35 | 36 | assert.strictEqual( 37 | eventData._blockHeight.eq(blockHeight), 38 | true, 39 | `Block height from event ${eventData._blockHeight}` 40 | + ` is different from expected ${blockHeight} `, 41 | ); 42 | 43 | assert.strictEqual( 44 | eventData._stateRoot, 45 | stateRoot, 46 | `State root from event ${eventData._stateRoot}` 47 | + ` is different from expected ${stateRoot} `, 48 | ); 49 | } 50 | } 51 | 52 | module.exports = AnchorStateRootAssertion; 53 | -------------------------------------------------------------------------------- /test_integration/lib/prove_gateway_assertion.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const assert = require('assert'); 22 | 23 | /** 24 | * Class to assert prove gateway. 25 | */ 26 | class ProveGatewayAssertion { 27 | /** 28 | * 29 | * @param {Object} event Decoded event for Gateway Proven. 30 | * @param {BN} blockHeight Block height at which prove gateway is done. 31 | * @param {string} storageRoot Storage root of gateway account at give 32 | * height. 33 | * @param {string}gateway Gateway address 34 | */ 35 | static verify(event, blockHeight, storageRoot, gateway) { 36 | const eventData = event.GatewayProven; 37 | 38 | assert.strictEqual( 39 | eventData._blockHeight.eq(blockHeight), 40 | true, 41 | `Block height from event ${eventData._blockHeight.toString(10)} 42 | is different from expected ${blockHeight} `, 43 | ); 44 | 45 | assert.strictEqual( 46 | eventData._storageRoot, 47 | storageRoot, 48 | `Storage root from event ${eventData._storageRoot} 49 | is different from expected ${storageRoot} `, 50 | ); 51 | 52 | assert.strictEqual( 53 | eventData._wasAlreadyProved, 54 | false, 55 | 'Already proven should be false', 56 | ); 57 | 58 | assert.strictEqual( 59 | eventData._gateway, 60 | gateway, 61 | 'Proven gateway must match.', 62 | ); 63 | } 64 | } 65 | 66 | module.exports = ProveGatewayAssertion; 67 | -------------------------------------------------------------------------------- /test_integration/main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT_NAME='mosaic_integration_tests' 4 | 5 | docker-compose --project-name $PROJECT_NAME up & 6 | sleep 10 7 | truffle --network integration_origin exec integration_tests.js 8 | TEST_STATUS=$? 9 | docker-compose --project-name $PROJECT_NAME down 10 | exit $TEST_STATUS 11 | -------------------------------------------------------------------------------- /tools/blue_deployment/cli/checks.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const colors = require('colors/safe'); 22 | 23 | /** 24 | * Check if the provided address contains code. 25 | * 26 | * @param {object} web3 The web3 instance to use. 27 | * @param {string} address The address to check whether it contains 28 | * contract code. 29 | */ 30 | const checkAddressForCode = async (web3, address) => { 31 | const contractCode = await web3.eth.getCode(address); 32 | if (!contractCode) { 33 | console.warn(colors.red('There is no contract present at the specified address!')); 34 | } 35 | }; 36 | 37 | module.exports = { 38 | checkAddressForCode, 39 | }; 40 | -------------------------------------------------------------------------------- /tools/build_package.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** 24 | * @file This file runs as part of the npm packaging process. 25 | * 26 | * It reads a set number of contracts from the truffle build directory and 27 | * extracts ABI and BIN of each contract. The extracted information is added to 28 | * a new object that is finally serialized to disk. That JSON file will be 29 | * exported by this package. 30 | * 31 | * To add a contract to the published package, add its name to array of contract 32 | * names. 33 | */ 34 | 35 | const fs = require("fs-extra"); 36 | const path = require('path'); 37 | 38 | const contractNames = [ 39 | 'Anchor', 40 | 'CoGatewayUtilityTokenInterface', 41 | 'EIP20CoGateway', 42 | 'EIP20Gateway', 43 | 'EIP20Interface', 44 | 'EIP20Token', 45 | 'GatewayLib', 46 | 'MerklePatriciaProof', 47 | 'MessageBus', 48 | 'Organization', 49 | 'OrganizationInterface', 50 | 'Organized', 51 | 'OSTPrime', 52 | 'StateRootInterface', 53 | 'UtilityToken', 54 | 'UtilityTokenInterface', 55 | 'OSTComposer', 56 | 'StakerProxy', 57 | 'RedeemPool', 58 | 'RedeemerProxy', 59 | ]; 60 | 61 | const contracts = {}; 62 | 63 | contractNames.forEach((contract) => { 64 | const contractPath = path.join( 65 | __dirname, 66 | `../build/contracts/${contract}.json`, 67 | ); 68 | 69 | if (!fs.existsSync(contractPath)) { 70 | throw new Error( 71 | `Cannot read file ${contractPath}.` 72 | + 'Truffle compile must be run before building the package.' 73 | + 'That should be done automatically when running `npm publish`.', 74 | ); 75 | } 76 | 77 | const contractFile = fs.readFileSync(contractPath); 78 | const metaData = JSON.parse(contractFile); 79 | 80 | contracts[contract] = {}; 81 | contracts[contract].abi = metaData.abi; 82 | 83 | if (metaData.bytecode !== '0x') { 84 | contracts[contract].bin = metaData.bytecode; 85 | } 86 | }); 87 | 88 | fs.ensureDirSync('contract_build'); 89 | fs.writeFileSync('contract_build/contracts.json', JSON.stringify(contracts)); 90 | -------------------------------------------------------------------------------- /tools/contract_interact_generator.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Copyright 2019 OpenST Ltd. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // ---------------------------------------------------------------------------- 18 | // 19 | // http://www.simpletoken.org/ 20 | // 21 | // ---------------------------------------------------------------------------- 22 | 23 | /** 24 | * This file reads the contents from `contract_build/contracts.json` and 25 | * auto-generates the contract interacts factory methods. 26 | */ 27 | 28 | const fs = require('fs'); 29 | const path = require('path'); 30 | 31 | const contractPath = path.join( 32 | __dirname, 33 | `../contract_build/contracts.json`, 34 | ); 35 | 36 | // Check if the contract.json file exists. 37 | if (!fs.existsSync(contractPath)) { 38 | throw new Error( 39 | `Cannot read file ${contractPath}.` 40 | + 'Build package must run before generating contract interacts.' 41 | + 'That should be done automatically when running `npm publish`.', 42 | ); 43 | } 44 | 45 | // This variable holds all the import statements as string. 46 | let imports = 'import { ContractOptions } from \'web3-eth-contract\';\nimport * as contracts from \'../contract_build/contracts.json\';\n'; 47 | 48 | // This variable holds all the interact factor methods as string. 49 | let interacts = `const Interacts = {\n`; 50 | 51 | // Get all the contract names. 52 | const contractNames = Object.keys(JSON.parse(fs.readFileSync(contractPath))); 53 | 54 | contractNames.forEach((contract) => { 55 | const declarationFilePath = path.join( 56 | __dirname, 57 | `../interacts/${contract}.d.ts`, 58 | ); 59 | if (fs.existsSync(declarationFilePath)) { 60 | imports = `${ imports }import { ${contract} } from \'./${contract}\';\n`; 61 | 62 | interacts = `${ interacts } 63 | /** 64 | * ${contract} contract interact object 65 | * @param web3 Web3 object. 66 | * @param address ${contract} contract address. 67 | * @param options Contract options. 68 | * 69 | * @returns The ${contract} contract interact object. 70 | */ 71 | get${contract}: (web3: any, address?: string, options?: ContractOptions): ${contract} => { 72 | const jsonInterface = contracts.${contract}.abi; 73 | const contract = new web3.eth.Contract(jsonInterface, address, options); 74 | return contract as ${contract}; 75 | },\n`; 76 | } 77 | }); 78 | 79 | interacts = `${ interacts }\n}; 80 | 81 | export default Interacts; 82 | 83 | `; 84 | 85 | // Create the file. 86 | fs.writeFileSync( 87 | 'interacts/Interacts.ts', 88 | `${ imports }\n${interacts}` 89 | ); 90 | -------------------------------------------------------------------------------- /tools/deployment_tool/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | // 17 | // http://www.simpletoken.org/ 18 | // 19 | // ---------------------------------------------------------------------------- 20 | 21 | const { Contract } = require('./Contract'); 22 | const { ContractRegistry } = require('./ContractRegistry'); 23 | const { 24 | IncrementingAddressGenerator, 25 | IncrementingNonceAddressGenerator, 26 | } = require('./address_generators'); 27 | const { 28 | deployContracts, 29 | UnlockedWeb3Signer, 30 | } = require('./utils'); 31 | 32 | module.exports = { 33 | Contract, 34 | ContractRegistry, 35 | IncrementingAddressGenerator, 36 | IncrementingNonceAddressGenerator, 37 | UnlockedWeb3Signer, 38 | deployContracts, 39 | }; 40 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/generate.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as path from 'path'; 3 | 4 | import FuzzyProofGenerator from './src/FuzzyProofGenerator'; 5 | import ProofData from './src/ProofData'; 6 | import patterns from './patterns'; 7 | 8 | interface HexProof { 9 | pattern: string; 10 | value: string; 11 | encodedPath: string; 12 | rlpParentNodes: string; 13 | root: string; 14 | } 15 | 16 | /** Converts a buffer to a hex string with a leading 0x. */ 17 | function bufferToHex(buffer: Buffer): string { 18 | return `0x${buffer.toString('hex')}`; 19 | } 20 | 21 | /** Converts a proof to a hex proof. */ 22 | function proofToHexProof(proof: ProofData): HexProof { 23 | return { 24 | pattern: proof.pattern, 25 | value: bufferToHex(proof.value), 26 | encodedPath: bufferToHex(proof.encodedPath), 27 | rlpParentNodes: bufferToHex(proof.rlpParentNodes), 28 | root: bufferToHex(proof.root), 29 | }; 30 | } 31 | 32 | const proofs: ProofData[] = []; 33 | 34 | // Run 4 times to generate more data. 35 | for (let i = 0; i < 4; i += 1) { 36 | patterns.forEach( 37 | (pattern: string): number => proofs.push(FuzzyProofGenerator.generateByPattern(pattern)), 38 | ); 39 | } 40 | 41 | // Convert to hex to be in line with the rest of the code base. 42 | const hexProofs: HexProof[] = proofs.map( 43 | (proof: ProofData): HexProof => proofToHexProof(proof), 44 | ); 45 | 46 | const filePath: string = path.join( 47 | __dirname, 48 | '..', 49 | '..', 50 | 'test', 51 | 'data', 52 | 'generatedProofData.json', 53 | ); 54 | 55 | fs.writeFileSync(filePath, JSON.stringify(hexProofs)); 56 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/patterns.ts: -------------------------------------------------------------------------------- 1 | const patterns: string[] = [ 2 | 'l', 3 | 'bl', 4 | 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl', 5 | 'ebl', 6 | 'bebl', 7 | 'bbebbl', 8 | 'bebbbbl', 9 | 'bbbebbbbbl', 10 | 'ebebl', 11 | 'ebebebebebl', 12 | 'bbebbebebebebbbebebl', 13 | 'bebb', 14 | 'bebebb', 15 | 'ebb', 16 | 'ebebebebbb', 17 | ]; 18 | 19 | export { patterns as default }; 20 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/src/BranchNode.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import NodeType from './Types'; 18 | import NodeBase from './NodeBase'; 19 | 20 | import assert = require('assert'); 21 | 22 | type BranchKeys = Buffer[]; 23 | 24 | /** Represents a branch node of Modified Merkle Patricia Trie. */ 25 | class BranchNode extends NodeBase { 26 | 27 | /* Storage */ 28 | 29 | public readonly keys: BranchKeys; 30 | 31 | public readonly value: Buffer; 32 | 33 | 34 | /* Public Functions */ 35 | 36 | /** 37 | * Creates a branch node. 38 | * 39 | * Requires: 40 | * - keys array's length is 16. 41 | * 42 | * @param keys Keys array of a branch node. 43 | * @param value A value to store in a branch node. 44 | * 45 | * @remarks 46 | * See: https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization 47 | */ 48 | public constructor(keys: BranchKeys, value: Buffer) { 49 | super(NodeType.Branch); 50 | 51 | assert( 52 | keys.length === 16, 53 | 'Branch node\'s keys length is not 16.', 54 | ); 55 | 56 | this.keys = keys; 57 | this.value = value; 58 | } 59 | 60 | /** 61 | * Returns a raw representation of an underlying data of a branch node as a 62 | * buffers array: 63 | * [...this.keys, this.value] 64 | * 65 | * @remarks 66 | * See: https://github.com/ethereum/wiki/wiki/Patricia-Tree#optimization 67 | * See: https://github.com/ethereum/wiki/wiki/Patricia-Tree#specification-compact-encoding-of-hex-sequence-with-optional-terminator 68 | */ 69 | public raw(): Buffer[] { 70 | const raw: Buffer[] = [...this.keys, this.value]; 71 | assert( 72 | raw.length === 17, 73 | 'Branch node\'s raw representation length is not 17.', 74 | ); 75 | return raw; 76 | } 77 | } 78 | 79 | export { 80 | BranchKeys, 81 | BranchNode, 82 | }; 83 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/src/NodeBase.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import NodeType from './Types'; 18 | 19 | import rlp = require('rlp'); 20 | import ethUtil = require('ethereumjs-util'); 21 | 22 | /** Acts as a parent class for all nodes' types. */ 23 | abstract class NodeBase { 24 | /* Storage */ 25 | 26 | public readonly type: NodeType; 27 | 28 | 29 | /* Public Functions */ 30 | 31 | /** Returns a raw representation of an underlying data without encoding. */ 32 | public abstract raw(): Buffer[]; 33 | 34 | /** Returns a serialized representation of an underlying data by rlp encoding. */ 35 | public serialize(): Buffer { 36 | return rlp.encode(this.raw()); 37 | } 38 | 39 | /** Returns a hash of an underlying data. */ 40 | public hash(): Buffer { 41 | const s: Buffer = this.serialize(); 42 | return ethUtil.keccak256(s); 43 | } 44 | 45 | 46 | /* Protected Functions */ 47 | 48 | protected constructor(type: NodeType) { 49 | this.type = type; 50 | } 51 | } 52 | 53 | export { NodeBase as default }; 54 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/src/ProofData.ts: -------------------------------------------------------------------------------- 1 | export default interface ProofData { 2 | pattern: string; 3 | value: Buffer; 4 | encodedPath: Buffer; 5 | rlpParentNodes: Buffer; 6 | root: Buffer; 7 | } 8 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/src/Types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | /** Enumeration for node types. */ 18 | enum NodeType { 19 | Branch = 'Branch', 20 | Extension = 'Extension', 21 | Leaf = 'Leaf', 22 | } 23 | 24 | export default NodeType; 25 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/ExtensionNode/encodeCompact.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import 'mocha'; 18 | import { assert } from 'chai'; 19 | import ExtensionNode from '../../src/ExtensionNode'; 20 | 21 | describe('ExtensionNode::encodeCompact', (): void => { 22 | it('Reverts if a buffer is empty.', (): void => { 23 | assert.throws( 24 | (): Buffer => ExtensionNode.encodeCompact(Buffer.alloc(0)), 25 | 'A nibble path to encode compact is empty.', 26 | ); 27 | }); 28 | 29 | it('Checks an odd-length buffer conversion.', (): void => { 30 | assert.deepEqual( 31 | ExtensionNode.encodeCompact(Buffer.from([1, 2, 3, 4, 5])), 32 | Buffer.from(String.fromCharCode(0x11, 0x23, 0x45)), 33 | ); 34 | }); 35 | 36 | it('Checks an even-length buffer conversion.', (): void => { 37 | assert.deepEqual( 38 | ExtensionNode.encodeCompact(Buffer.from([0, 1, 2, 3, 4, 5])), 39 | Buffer.from(String.fromCharCode(0x00, 0x01, 0x23, 0x45)), 40 | ); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/LeafNode/encodeCompact.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import 'mocha'; 18 | import { assert } from 'chai'; 19 | import LeafNode from '../../src/LeafNode'; 20 | 21 | describe('LeafNode::encodeCompact', (): void => { 22 | it('Reverts if a buffer is empty.', (): void => { 23 | assert.throws( 24 | (): Buffer => LeafNode.encodeCompact(Buffer.alloc(0)), 25 | 'A nibble path to encode compact is empty.', 26 | ); 27 | }); 28 | 29 | it('Checks an odd-length buffer conversion.', (): void => { 30 | assert.deepEqual( 31 | LeafNode.encodeCompact(Buffer.from([0xF, 1, 0xC, 0xB, 8])), 32 | Buffer.from([0x3F, 0x1C, 0xB8]), 33 | ); 34 | }); 35 | 36 | it('Checks an even-length buffer conversion.', (): void => { 37 | assert.deepEqual( 38 | LeafNode.encodeCompact(Buffer.from([0, 0xF, 1, 0xC, 0xB, 8])), 39 | Buffer.from([0x20, 0xF, 0x1C, 0xB8]), 40 | ); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/Nibbles/assertNibbleArray.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import 'mocha'; 18 | import { assert } from 'chai'; 19 | import Nibbles from '../../src/Nibbles'; 20 | 21 | describe('Nibbles::assertNibbleArray', (): void => { 22 | it('Reverts on a negative input.', (): void => { 23 | assert.throws( 24 | (): void => Nibbles.assertNibbleArray(Buffer.from([-1])), 25 | 'An array is not a nibble array.', 26 | ); 27 | }); 28 | 29 | it('Reverts on an input bigger than 0x0F.', (): void => { 30 | assert.throws( 31 | (): void => Nibbles.assertNibbleArray(Buffer.from([0xF + 1])), 32 | 'An array is not a nibble array.', 33 | ); 34 | }); 35 | 36 | it('Checks an empty array.', (): void => { 37 | assert.doesNotThrow( 38 | (): void => Nibbles.assertNibbleArray(Buffer.alloc(0)), 39 | ); 40 | }); 41 | 42 | it('Checks a valid array.', (): void => { 43 | assert.doesNotThrow( 44 | (): void => Nibbles.assertNibbleArray(Buffer.from([ 45 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 46 | ])), 47 | ); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/Nibbles/nibblesToBuffer.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import 'mocha'; 18 | import { assert } from 'chai'; 19 | import Nibbles from '../../src/Nibbles'; 20 | 21 | describe('Nibbles::nibblesToBuffer', (): void => { 22 | it('Reverts if a buffer\'s length is odd.', (): void => { 23 | assert.throws( 24 | (): Buffer => Nibbles.nibblesToBuffer(Buffer.from([1])), 25 | 'Nibbles array\'s length is odd.', 26 | ); 27 | 28 | assert.throws( 29 | (): Buffer => Nibbles.nibblesToBuffer(Buffer.from([1, 2, 3])), 30 | 'Nibbles array\'s length is odd.', 31 | ); 32 | }); 33 | 34 | it('Checks an empty buffer conversion.', (): void => { 35 | assert.deepEqual( 36 | Nibbles.nibblesToBuffer(Buffer.alloc(0)), 37 | Buffer.alloc(0), 38 | ); 39 | }); 40 | 41 | it('Checks a one element buffer conversion.', (): void => { 42 | assert.deepEqual( 43 | Nibbles.nibblesToBuffer(Buffer.from([6, 4])), 44 | Buffer.from('d'), 45 | ); 46 | }); 47 | 48 | it('Checks a multielement string conversion.', (): void => { 49 | assert.deepEqual( 50 | Nibbles.nibblesToBuffer(Buffer.from([6, 3, 6, 0xF, 6, 9, 6, 0xE])), 51 | Buffer.from('coin'), 52 | ); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/Nibbles/toNibbles.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019 OpenST Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ---------------------------------------------------------------------------- 16 | 17 | import 'mocha'; 18 | import { assert } from 'chai'; 19 | 20 | import Nibbles from '../../src/Nibbles'; 21 | 22 | describe('Nibbles::toNibbles', (): void => { 23 | it('Checks an empty string conversion.', (): void => { 24 | const nibbleArray: Buffer = Nibbles.toNibbles(Buffer.from('')); 25 | assert.deepEqual( 26 | nibbleArray, 27 | Buffer.alloc(0), 28 | ); 29 | }); 30 | 31 | it('Checks a one element string conversion.', (): void => { 32 | const nibbleArray: Buffer = Nibbles.toNibbles(Buffer.from([0x64])); 33 | assert.deepEqual( 34 | nibbleArray, 35 | Buffer.from([6, 4]), 36 | ); 37 | }); 38 | 39 | it('Checks a multielement string conversion.', (): void => { 40 | const nibbleArray: Buffer = Nibbles.toNibbles(Buffer.from([0x63, 0x6F, 0x69, 0x6E])); 41 | assert.deepEqual( 42 | nibbleArray, 43 | Buffer.from([6, 3, 6, 0xF, 6, 9, 6, 0xE]), 44 | ); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tools/fuzzy_proof_generator_tool/test/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./node_modules/.bin/tsc -p ./tools/tools_tsconfig.json && \ 4 | mocha -r ts-node/register tools/fuzzy_proof_generator_tool/test/**/*.test.ts && \ 5 | truffle test ./tools/fuzzy_proof_generator_tool/test/FuzzyProofGenerator/generate.js && \ 6 | truffle test ./tools/fuzzy_proof_generator_tool/test/FuzzyProofGenerator/generateByPattern.js 7 | -------------------------------------------------------------------------------- /tools/merge_chainspec_accounts.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | // Called like this: 3 | // node merge_chainspec_accounts.js chainspec.json accounts.json 4 | const fs = require('fs'); 5 | 6 | const chainspecPath = process.argv[2]; 7 | const accountsPath = process.argv[3]; 8 | 9 | const chainspec = JSON.parse(fs.readFileSync(chainspecPath)); 10 | const accounts = JSON.parse(fs.readFileSync(accountsPath)); 11 | 12 | Object.entries(accounts).forEach(([address, obj]) => { 13 | if (chainspec.accounts[address]) { 14 | console.warn(`Account at address ${address} already exists.`); 15 | } 16 | chainspec.accounts[address] = obj; 17 | }); 18 | 19 | // Pretty print as JSON 20 | process.stdout.write(JSON.stringify(chainspec, null, 4)); 21 | -------------------------------------------------------------------------------- /tools/runGanacheCli.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | node_modules/.bin/ganache-cli \ 3 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea0,10000000000000000000000000000000" \ 4 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea1,10000000000000000000000000000000" \ 5 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea2,10000000000000000000000000000000" \ 6 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea3,10000000000000000000000000000000" \ 7 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea4,10000000000000000000000000000000" \ 8 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea5,10000000000000000000000000000000" \ 9 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea6,10000000000000000000000000000000" \ 10 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea7,10000000000000000000000000000000" \ 11 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea8,10000000000000000000000000000000" \ 12 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5ea9,0" \ 13 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb0,10000000000000000000000000000000" \ 14 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb1,10000000000000000000000000000000" \ 15 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb2,10000000000000000000000000000000" \ 16 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb3,10000000000000000000000000000000" \ 17 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb4,10000000000000000000000000000000" \ 18 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb5,10000000000000000000000000000000" \ 19 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb6,10000000000000000000000000000000" \ 20 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb7,10000000000000000000000000000000" \ 21 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb8,10000000000000000000000000000000" \ 22 | --account="0x8fbbbaceff30d4eea3e2ffa2dfedc3c053f78c1f53103e4ddc31309e6b1d5eb9,0" \ 23 | --gasLimit 12000000 24 | -------------------------------------------------------------------------------- /tools/test_range.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019 OpenST Ltd. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ---------------------------------------------------------------------------- 18 | # 19 | # http://www.simpletoken.org/ 20 | # 21 | # ---------------------------------------------------------------------------- 22 | 23 | ### 24 | # Runs tests sequentially for a range of decimal values. 25 | # 26 | # Example run with decimals 12 - 18 (inclusive): 27 | # 28 | # ```bash 29 | # npm run test:range -- 12 18 30 | # ``` 31 | # 32 | # You can provide only one argument and the tests will run for that specific 33 | # decimal. 34 | ### 35 | 36 | # Tracking the exit code to run further tests if they fail for a spcefic decimal. 37 | EXIT_CODE=0 38 | 39 | # Tracking failed decimals for error output. 40 | FAILED_DECIMALS="" 41 | 42 | function handle_error { 43 | # On first iteration, no extra comma 44 | if [ $EXIT_CODE -eq 0 ]; 45 | then 46 | FAILED_DECIMALS="$1" 47 | else 48 | FAILED_DECIMALS="${FAILED_DECIMALS}, $1" 49 | fi 50 | EXIT_CODE=1 51 | } 52 | 53 | function handle_exit { 54 | if [ $EXIT_CODE -ne 0 ]; 55 | then 56 | echo "" 57 | echo "### Errors for the following decimals:" 58 | echo "${FAILED_DECIMALS}" 59 | echo "" 60 | else 61 | echo "" 62 | echo "### Done" 63 | echo "" 64 | fi 65 | 66 | exit $EXIT_CODE 67 | } 68 | 69 | echo "" 70 | 71 | if [ $# -ne 1 ] && [ $# -ne 2 ]; 72 | then 73 | echo "Wrong number of parameters given." 74 | echo "Run with two arguments: start and end of range inclusive." 75 | echo "Example:" 76 | echo "npm run test:range -- 16 20" 77 | echo "" 78 | echo "If you provide only one argument, the tests will be run for that value." 79 | echo "" 80 | exit 1 81 | fi 82 | 83 | # Start and end values should be provided on the command line. 84 | START=$1 85 | 86 | if [ $# -eq 1 ]; 87 | then 88 | END=$START 89 | else 90 | END=$2 91 | fi 92 | 93 | for DECIMALS in $(seq "${START}" "${END}"); 94 | do 95 | echo "### Running tests with ${DECIMALS} decimals." 96 | export OPENST_DECIMALS=$DECIMALS 97 | npm test || handle_error $DECIMALS 98 | done 99 | 100 | handle_exit 101 | 102 | -------------------------------------------------------------------------------- /tools/tools_tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "alwaysStrict": true, 6 | "strictNullChecks": true, 7 | "strictBindCallApply": true, 8 | "strictFunctionTypes": true, 9 | "strictPropertyInitialization": true, 10 | "noImplicitThis": true, 11 | "noImplicitAny": true, 12 | "noImplicitReturns": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noUnusedLocals": true, 15 | "noUnusedParameters": true, 16 | "noErrorTruncation": true, 17 | "sourceMap": true, 18 | "types": [ 19 | "chai", 20 | "node", 21 | "mocha" 22 | ], 23 | "resolveJsonModule": true 24 | }, 25 | "include": [ 26 | "./fuzzy_proof_generator_tool/src/*.ts" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: 'localhost', 5 | network_id: '*', // Match any network id 6 | port: 8545, 7 | gas: 8000000, 8 | gasPrice: 0x01, 9 | }, 10 | integration_origin: { 11 | host: 'localhost', 12 | network_id: '*', 13 | port: 8546, 14 | }, 15 | integration_auxiliary: { 16 | host: 'localhost', 17 | network_id: '*', 18 | port: 8547, 19 | }, 20 | coverage: { 21 | host: 'localhost', 22 | network_id: '*', 23 | port: 8555, // <-- If you change this, also set the port option in .solcover.js. 24 | gas: 0xfffffffffff, // <-- Use this high gas value 25 | gasPrice: 0x01, // <-- Use this low gas price 26 | }, 27 | }, 28 | compilers: { 29 | solc: { 30 | settings: { 31 | optimizer: { 32 | enabled: true, 33 | // set to same number of runs as openst-platform 34 | // so that integration tests on openst-protocol 35 | // give accurate gas measurements 36 | runs: 200, 37 | }, 38 | }, 39 | }, 40 | }, 41 | }; 42 | -------------------------------------------------------------------------------- /ts-generator.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "generator":"typechain", 4 | "files":"./build/**/*/!(Migrations.json|MessageBus.json|BytesLib.json|SafeMath.json|MetaBlock.json|RLP.json|RLPEncode.sol|*Mock.json|Mock*|Test*|*Test.json|*Interface.json|Spy*)", 5 | "target":"web3-1.0.0", 6 | "outDir":"interacts" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "compilerOptions": { 4 | "target": "es6", 5 | "module": "commonjs", 6 | "alwaysStrict": true, 7 | "strictNullChecks": true, 8 | "strictBindCallApply": true, 9 | "strictFunctionTypes": true, 10 | "strictPropertyInitialization": true, 11 | "noImplicitThis": true, 12 | "noImplicitAny": false, 13 | "noImplicitReturns": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "noUnusedLocals": true, 16 | "noUnusedParameters": true, 17 | "noErrorTruncation": true, 18 | "sourceMap": true, 19 | "resolveJsonModule": true, 20 | "outDir": "./dist", 21 | "declaration": true, 22 | "skipLibCheck": true 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "tools", 27 | "dist", 28 | "contracts" 29 | ] 30 | } 31 | --------------------------------------------------------------------------------