const path = require('path')
const authereumProxyAbi = require(path.resolve(__dirname, '../../build/contracts/AuthereumProxy.json'))

module.exports = {
  /**
   * ETH Values
   */

  ONE_ETHER: web3.utils.toWei('1', 'ether'),
  TWO_ETHER: web3.utils.toWei('2', 'ether'),
  THREE_ETHER: web3.utils.toWei('3', 'ether'),
  FOUR_ETHER: web3.utils.toWei('4', 'ether'),
  TEN_ETHER: web3.utils.toWei('10', 'ether'),
  TWENTY_ETHER: web3.utils.toWei('20', 'ether'),
  STARTING_ETHER: web3.utils.toWei('1000000000000000000', 'ether'),

  /**
   * Contract Data
   */

  CONTRACTS: {
    AUTHEREUM_ACCOUNT: {
      NAME: 'Authereum Account',
      VERSIONS: [
        '2019102500',
        '2019111500',
        '2019122000',
        '2019122100',
        '2020010900',
        '2020020200',
        '2020021700',
        '2020060100',
        '2020070100'
      ]
    },
    AUTHEREUM_PROXY_FACTORY: {
      NAME: 'Authereum Proxy Factory',
      VERSIONS: [
        '2019102500',
        '2019111500',
        '2020070100'
      ]
    },
    AUTHEREUM_ENS_MANAGER: {
      NAME: 'Authereum ENS Manager',
      VERSIONS: [
        '2019102500',
        '2019111500',
        '2020070100'
      ]
    },
    AUTHEREUM_ENS_RESOLVER: {
      NAME: 'Authereum ENS Resolver',
      VERSIONS: [
        '2019102500',
        '2019111500',
        '2020070100'
      ]
    },
    AUTHEREUM_DELEGATE_KEY_MODULE: {
      NAME: 'Authereum Delegate Key Module',
      VERSIONS:[
        '2020070100'
      ]
    },
    AUTHEREUM_RECOVERY_MODULE: {
      NAME: 'Authereum Recovery Module',
      VERSIONS: [
        '2020070100'
      ]
    },
    AUTHEREUM_LOGIN_KEY_VALIDATOR: {
      NAME: 'Authereum Login Key Validator',
      VERSIONS: [
        '2020070100'
      ]
    }
  },
  AUTHEREUM_PROXY_CREATION_CODE: authereumProxyAbi.bytecode,
  AUTHEREUM_PROXY_CREATION_CODE_HASH: web3.utils.soliditySha3(authereumProxyAbi.bytecode),
  // This is generated by placing an event in the contract that reads the `extcodesize`
  AUTHEREUM_PROXY_RUNTIME_CODE_HASH: {
    '1571517085': web3.utils.soliditySha3(authereumProxyAbi.deployedBytecode)
  },
  SALT: 123,
  DEFAULT_LABEL: 'myName',
  DEFAULT_DEPLOYMENT_COST: 0,

  /**
   * Tx Data
   */

  GAS_PRICE: 20000000000,
  GAS_LIMIT: 500000,
  GAS_LIMIT_GANACHE_BUG: 2300,
  // NOTE: As of 20200605, ganache does not allow for customizable chain ID. It is 1 by default.
  CHAIN_ID: 1,
  DATA: '0x00',
  DEFAULT_GAS_OVERHEAD: 50000,
  DEFAULT_LOGIN_KEY_EXPIRATION_TIME_DATA: web3.eth.abi.encodeParameter('uint256', 9999999999),

  /**
   * Signing Data
   */

  AUTH_KEY_0_PRIV_KEY: '0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1',
  LOGIN_KEY_0_PRIV_KEY: '0x77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f',

  /**
   * Tokens
   */

  DEFAULT_TOKEN_SUPPLY: 10,
  DEFAULT_TOKEN_SYMBOL: 'AUTH',
  DEFAULT_TOKEN_NAME: 'AuthereumToken',
  DEFAULT_TOKEN_DECIMALS: 18,
  DEFAULT_TOKEN_RATE: 150,

  /**
   * Timing
   */

  ONE_DAY: 86400,
  ONE_WEEK: 86400 * 7,
  ONE_MONTH: 86400 * 7 * 4,

  /**
   * Revert Messages
   */

   REVERT_MSG: {
    // Account
    BA_AUTH_KEY_ALREADY_ADDED: 'BA: Auth key already added',
    BA_AUTH_KEY_CANNOT_BE_SELF: 'BA: Cannot add self as an auth key',
    BA_AUTH_KEY_NOT_YET_ADDED: 'BA: Auth key not yet added',
    BA_CANNOT_REMOVE_LAST_AUTH_KEY: 'BA: Cannot remove last auth key',
    BA_BLOCKED_BY_FIREWALL: 'BA: Transaction blocked by the firewall',
    BA_INSUFFICIENT_GAS_TRANSACTION: 'BA: Insufficient gas for transaction',
    BA_INSUFFICIENT_GAS_ETH: 'BA: Insufficient gas (ETH) for refund',
    BA_INSUFFICIENT_GAS_TOKEN: 'BA: Insufficient gas (token) for refund',
    // NOTE: This message is used when an internal, atomic transaction call fails silently
    BA_SILENT_REVERT: 'BA: Transaction reverted silently',
    BA_REQUIRE_AUTH_KEY: 'BA: Only auth key allowed',
    BA_REQUIRE_SELF: 'BA: Only self allowed',
    BA_REQUIRE_AUTH_KEY_OR_SELF: 'BA: Only auth key or self allowed',

    AI_IMPROPER_INIT_ORDER: 'AI: Improper initialization order',

    LKMTA_LOGIN_KEY_NOT_ABLE_TO_CALL_SELF: 'LKMTA: Login key is not able to call self',
    LKMTA_LOGIN_KEY_NOT_ABLE_TO_CALL_AUTH_KEY: 'LKMTA: Login key is not able to call an Auth key',
    LKMTA_AUTH_KEY_INVALID: 'LKMTA: Auth key is invalid',
    LKMTA_LOGIN_KEY_EXPIRED: 'LKMTA: Login key is expired',

    LKV_LOGIN_KEY_EXPIRED: 'LKV: Login key is expired',
    LKV_INVALID_RELAYER: 'LKV: Invalid relayer',
    LKV_RELAYER_ALREADY_ADDED: 'LKV: Relayer has already been added',
    LKV_NOT_A_RELAYER: 'LKV: Address is not a relayer',

    AKMTA_AUTH_KEY_INVALID: 'AKMTA: Auth key is invalid',

    BMTA_NOT_LARGE_ENOUGH_TX_GASPRICE: 'BMTA: Not a large enough tx.gasprice',
    BMTA_ATOMIC_CALL_OUT_OF_GAS: "BMTA: Atomic call ran out of gas",

    AU_NON_CONTRACT_ADDRESS: 'AU: Cannot set a proxy implementation to a non-contract address',

    ERC1271_INVALID_SIG_LENGTH: 'ERC1271: Invalid isValidSignature _signature length',
    ERC1271_INVALID_AUTH_KEY_SIG: 'ERC1271: Invalid isValidAuthKeySignature _signature length',
    ERC1271_INVALID_LOGIN_KEY_SIG: 'ERC1271: Invalid isValidLoginKeySignature _signature length',

    // Admin
    T_REQUIRE_TIMELOCK_CONTRACT: 'T: Only this contract can call this function',
    T_TIMELOCK_NOT_ABLE_TO_CHANGE: 'T: Change not able to be made',
    T_TIMELOCK_NOT_ABLE_TO_INITIATE_CHANGE: 'T: Change not able to be initiated',

    // Base
    O_MUST_BE_OWNER: 'O: Must be owner',
    O_NOT_NULL_ADDRESS: 'O: Address must not be null',
    M_NOT_NULL_ADDRESS: 'M: Address must not be null',
    M_MUST_BE_EXISTING_MANAGER: 'M: Target must be an existing manager',
    M_MUST_BE_MANAGER: 'M: Must be manager',

    // ENS
    AEM_MUST_SEND_FROM_FACTORY: 'AEM: Must be sent from the authereumFactoryAddress',
    AEM_ADDRESS_MUST_NOT_BE_NULL: 'AEM: Address must not be null',
    AEM_LABEL_OWNED: 'AEM: Label is already owned',

    // Test
    BT_WILL_FAIL: 'BT: Will fail',
    ERC777_NO_IMPLEMENTER: 'ERC777: token recipient contract has no implementer for ERC777TokensRecipient',

    // Upgradeability
    APF_EMPTY_INIT: 'APF: Empty initialization data',
    APF_UNSUCCESSFUL_INIT: 'APF: Unsuccessful account initialization',

    // Recovery Module
    ARM_INACTIVE_RECOVERY_ACCOUNT: 'ARM: Inactive recovery account',
    ARM_RECOVERY_MODULE_NOT_REGISTERED: 'ARM: Recovery module not registered to account',
    ARM_RECOVERY_ADDRESS_ALREADY_ADDED: 'ARM: Recovery address has already been added',
    ARM_RECOVERY_ADDRESS_CANNOT_BE_ZERO: 'ARM: Recovery address cannot be address(0)',
    ARM_RECOVERY_ADDRESS_CANNOT_BE_SELF: 'ARM: Cannot add self as recovery account',
    ARM_RECOVERY_ADDRESS_ALREADY_INACTIVE: 'ARM: Recovery address is already inactive',
    ARM_RECOVERY_ALREADY_IN_PROCESS: 'ARM: Recovery is already in process',
    ARM_AUTH_KEY_CANNOT_BE_ZERO: 'ARM: Auth Key cannot be address(0)',
    ARM_NO_RECOVERY_ATTEMPT: 'ARM: Recovery attempt does not exist',
    ARM_RECOVERY_DELAY_INCOMPLETE: 'ARM: Recovery attempt delay period has not completed',

    // Delegate Key Module
    ADKM_DELEGATE_KEY_NOT_ACTIVE: 'ADKM: Delegate Key is not active',
    ADKM_MODULE_NOT_REGISTERED: 'ADKM: Delegate Key module not registered to account',
    ADKM_DELEGATE_KEY_CANNOT_BE_ZERO: 'ADKM: Delegate Key cannot be address(0)',
    ADKM_LOCKED_PARAMETERS_LENGTHS_NOT_EQUAL: 'ADKM: lockedParameters must be the same length as lockedParameterValues',
    ADKM_VALUE_HIGHER_THAN_MAXIMUM: 'ADKM: Value is higher than maximum allowed value',
    ADKM_INVALID_FUNCTION_SELECTOR: 'ADKM: Invalid function selector',
    ADKM_INVALID_PARAMETER: 'ADKM: Invalid parameter',
    ADKM_TRANSACTION_DATA_TOO_SHORT: 'ADKM: Transaction data is too short',
    ADKM_ALREADY_REGISTERED: 'ADKM: Delegate Key is already registered',

    // General
    // NOTE: This message is used when an auth key transaction (not relayed) fails silently
    // NOTE: This message is used when the contract tries to `abi.decode` an invalid param
    GENERAL_REVERT: 'revert',
    // NOTE: This message is used when there is not a high enough gasLimit sent by the relayer
    EXCEEDS_GAS_LIMIT: 'base fee exceeds gas limit',
    // NOTE: This message is used when a executeMultipleTransactions or
    // executeMultipleMetaTransactions tx fails.
    // NOTE: This should prepend another error message
    AUTHEREUM_CALL_REVERT: 'Authereum Call Revert: '
  },

  /**
   * Other
   */

  ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
  ONE_ADDRESS: '0x0000000000000000000000000000000000000001',
  HASH_ZERO: '0x0000000000000000000000000000000000000000000000000000000000000000',
  BAD_DATA: '0xe855bd76',
  // This is the hash of Event('Will fail')
  FAILED_TX_DATA: `0x` +
  `08c379a000000000000000000000000000000000000000000000000000000000` +
  `0000002000000000000000000000000000000000000000000000000000000000` +
  `0000000957696c6c206661696c00000000000000000000000000000000000000` +
  `00000000`,
  FEE_VARIANCE: 9000000000000000,

  ERC1820_SIGNED_DEPLOY_TRANSACTION: `0x` +
  `f90a388085174876e800830c35008080b909e560806040523480156100105760` +
  `0080fd5b506109c5806100206000396000f3fe60806040523480156100105760` +
  `0080fd5b50600436106100a5576000357c010000000000000000000000000000` +
  `000000000000000000000000000090048063a41e7d5111610078578063a41e7d` +
  `51146101d4578063aabbb8ca1461020a578063b705676514610236578063f712` +
  `f3e814610280576100a5565b806329965a1d146100aa5780633d584063146100` +
  `e25780635df8122f1461012457806365ba36c114610152575b600080fd5b6100` +
  `e0600480360360608110156100c057600080fd5b50600160a060020a03813581` +
  `1691602081013591604090910135166102b6565b005b61010860048036036020` +
  `8110156100f857600080fd5b5035600160a060020a0316610570565b60408051` +
  `600160a060020a039092168252519081900360200190f35b6100e06004803603` +
  `604081101561013a57600080fd5b50600160a060020a03813581169160200135` +
  `166105bc565b6101c26004803603602081101561016857600080fd5b81019060` +
  `208101813564010000000081111561018357600080fd5b820183602082011115` +
  `61019557600080fd5b8035906020019184600183028401116401000000008311` +
  `17156101b757600080fd5b5090925090506106b3565b60408051918252519081` +
  `900360200190f35b6100e0600480360360408110156101ea57600080fd5b5080` +
  `35600160a060020a03169060200135600160e060020a0319166106ee565b6101` +
  `086004803603604081101561022057600080fd5b50600160a060020a03813516` +
  `9060200135610778565b61026c6004803603604081101561024c57600080fd5b` +
  `508035600160a060020a03169060200135600160e060020a0319166107ef565b` +
  `604080519115158252519081900360200190f35b61026c600480360360408110` +
  `1561029657600080fd5b508035600160a060020a03169060200135600160e060` +
  `020a0319166108aa565b6000600160a060020a038416156102cd57836102cf56` +
  `5b335b9050336102db82610570565b600160a060020a03161461033957604080` +
  `5160e560020a62461bcd02815260206004820152600f60248201527f4e6f7420` +
  `746865206d616e61676572000000000000000000000000000000000060448201` +
  `5290519081900360640190fd5b6103428361092a565b15610397576040805160` +
  `e560020a62461bcd02815260206004820152601a60248201527f4d757374206e` +
  `6f7420626520616e204552433136352068617368000000000000604482015290` +
  `519081900360640190fd5b600160a060020a038216158015906103b857506001` +
  `60a060020a0382163314155b156104ff5760405160200180807f455243313832` +
  `305f4143434550545f4d41474943000000000000000000000000815250601401` +
  `90506040516020818303038152906040528051906020012082600160a060020a` +
  `031663249cb3fa85846040518363ffffffff167c010000000000000000000000` +
  `0000000000000000000000000000000000028152600401808381526020018260` +
  `0160a060020a0316600160a060020a0316815260200192505050602060405180` +
  `83038186803b15801561047e57600080fd5b505afa158015610492573d600080` +
  `3e3d6000fd5b505050506040513d60208110156104a857600080fd5b50511461` +
  `04ff576040805160e560020a62461bcd02815260206004820181905260248201` +
  `527f446f6573206e6f7420696d706c656d656e742074686520696e7465726661` +
  `6365604482015290519081900360640190fd5b600160a060020a038181166000` +
  `81815260208181526040808320888452909152808220805473ffffffffffffff` +
  `ffffffffffffffffffffffffff19169487169485179055518692917f93baa6ef` +
  `bd2244243bfee6ce4cfdd1d04fc4c0e9a786abd3a41313bd352db15391a45050` +
  `5050565b600160a060020a038181166000908152600160205260408120549091` +
  `16151561059a5750806105b7565b50600160a060020a03808216600090815260` +
  `016020526040902054165b919050565b336105c683610570565b600160a06002` +
  `0a031614610624576040805160e560020a62461bcd0281526020600482015260` +
  `0f60248201527f4e6f7420746865206d616e6167657200000000000000000000` +
  `00000000000000604482015290519081900360640190fd5b81600160a060020a` +
  `031681600160a060020a0316146106435780610646565b60005b600160a06002` +
  `0a03838116600081815260016020526040808220805473ffffffffffffffffff` +
  `ffffffffffffffffffffff19169585169590951790945592519184169290917f` +
  `605c2dbf762e5f7d60a546d42e7205dcb1b011ebc62a61736a57c9089d3a4350` +
  `9190a35050565b60008282604051602001808383808284378083019250505092` +
  `5050506040516020818303038152906040528051906020012090505b92915050` +
  `565b6106f882826107ef565b610703576000610705565b815b600160a060020a` +
  `03928316600081815260208181526040808320600160e060020a031996909616` +
  `808452958252808320805473ffffffffffffffffffffffffffffffffffffffff` +
  `1916959097169490941790955590815260028452818120928152919092522080` +
  `5460ff19166001179055565b600080600160a060020a03841615610790578361` +
  `0792565b335b905061079d8361092a565b156107c357826107ad82826108aa56` +
  `5b6107b85760006107ba565b815b925050506106e8565b600160a060020a0390` +
  `8116600090815260208181526040808320868452909152902054169050929150` +
  `50565b6000808061081d857f01ffc9a700000000000000000000000000000000` +
  `00000000000000000000000061094c565b909250905081158061082d57508015` +
  `5b1561083d576000925050506106e8565b61084f85600160e060020a03196109` +
  `4c565b909250905081158061086057508015155b156108705760009250505061` +
  `06e8565b61087a858561094c565b909250905060018214801561088f57508060` +
  `01145b1561089f576001925050506106e8565b506000949350505050565b6001` +
  `60a060020a0382166000908152600260209081526040808320600160e060020a` +
  `03198516845290915281205460ff1615156108f2576108eb83836107ef565b90` +
  `506106e8565b50600160a060020a038083166000818152602081815260408083` +
  `20600160e060020a0319871684529091529020549091161492915050565b7bff` +
  `ffffffffffffffffffffffffffffffffffffffffffffffffffffff161590565b` +
  `6040517f01ffc9a7000000000000000000000000000000000000000000000000` +
  `000000008082526004820183905260009182919060208160248189617530fa90` +
  `519096909550935050505056fea165627a7a72305820377f4a2d4301ede9949f` +
  `163f319021a6e9c687c292a5e2b2c4734c126b524e6c00291ba0182018201820` +
  `1820182018201820182018201820182018201820182018201820a01820182018` +
  `201820182018201820182018201820182018201820182018201820`,
  ERC1820_DEPLOYER_ADDRESS: '0xa990077c3205cbDf861e17Fa532eeB069cE9fF96',
  ERC1820_REGISTRY_ADDRESS: '0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24',
  TOKENS_RECIPIENT_INTERFACE_HASH: '0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b',
  IMPLEMENTATION_SLOT: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
