OpenST / openst-contracts

OpenST is a framework for building token economies on Ethereum
Apache License 2.0
26 stars 19 forks source link

Update PricerRule.pay() unit test case to handle arbitrary decimals. #208

Closed deepesh-kn closed 5 years ago

deepesh-kn commented 5 years ago

Currently https://github.com/OpenST/openst-contracts/blob/develop/test/pricer_rule/pay.js handles the test case with 2 variations. Add flexibility to run the tests with arbitrary combinations of priceOracleDecimals and eip20TokenDecimals

For Pricer.pay unit test, create a config file that can contain decimal pairs for price oracle and token

"pay_config":[
    {"priceOracleDecimals": 18, "eip20TokenDecimals": 5},
    {"priceOracleDecimals": 3, "eip20TokenDecimals": 10},
    {"priceOracleDecimals": 13, "eip20TokenDecimals": 7}
  ]

In the pricerRule.pay there are 2 test cases that tests two variations. This can be changed to a single test.

https://github.com/OpenST/openst-contracts/blob/develop/test/pricer_rule/pay.js#L356 https://github.com/OpenST/openst-contracts/blob/develop/test/pricer_rule/pay.js#L483

Read the json file like const payConfig = process.env.PAY_CONFIG || <read the contents from the file>

Loop through the array of payConfig and execute the tests.

Assign the config and eip20TokenConfig from payConfig

const config = {
  requiredPriceOracleDecimals: payConfig.priceOracleDecimals,
};
const eip20TokenConfig = {
  decimals: payConfig.eip20TokenDecimals,
};
deepesh-kn commented 5 years ago

Create a followup ticket. Add expected result values in the config.