def deploy_link_oracle_api(): fantom_controller = FantomController(MAINNET) solidity_ctrl = SolidityController("v0.4.25") solidity_ctrl.compile(ROOT_DIR + "/contracts/LinkToken") link_addr = solidity_ctrl.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/LinkToken/LinkToken.sol:LinkToken", fantom_controller) print("link: " + link_addr) solidity_ctrl = SolidityController("v0.4.24") solidity_ctrl.compile(ROOT_DIR + "/contracts/Oracle/") oracle_addr = solidity_ctrl.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle", fantom_controller, link_addr) print("oracle: " + oracle_addr) solidity_ctrl.compile(ROOT_DIR + "/contracts/OracleConsumer/") test_addr = solidity_ctrl.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer", fantom_controller, link_addr) print("test: " + test_addr)
def deploy_oracle_testnet(): fantom_ctrl = FantomController(MAINNET) solidity_ctrl = SolidityController("0.4.24") solidity_ctrl.compile(ROOT_DIR + "/contracts/Oracle/") contract_addr = solidity_ctrl.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle", fantom_ctrl, fantom_ctrl.w3.toChecksumAddress(LINK_ADDR)) print(contract_addr)
def deploy_test_api(): okex_controller = OKExController(False) solidity_ctrl = SolidityController("v0.4.24") solidity_ctrl.compile(ROOT_DIR + "/contracts/OracleConsumer/") test_addr = solidity_ctrl.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer", okex_controller, LINK_ADDR) # "0x0a0f4b0D23F423E1e64100D0C2102f71E079B096", "0x234256711dB1e916c51aEcf1DF6351bcf246a24d" print(test_addr)
def test_chainlink_integration(): fantom_ctrl = FantomController(MAINNET) # solidity_ctrl = SolidityController("v0.8.1") # solidity_ctrl.compile(ROOT_DIR + "/contracts/WrappedLinkToken") # link_addr = solidity_ctrl.deploy(ROOT_DIR + "/contracts/WrappedLinkToken/LinkToken.sol:ChainLink", fantom_ctrl, # "LINK", "LINK", 18, fantom_ctrl.w3.toChecksumAddress(OWNER_ADDR)) solidity_ctrl = SolidityController("v0.4.24") solidity_ctrl.compile(ROOT_DIR + "/contracts/Oracle/") oracle_addr = solidity_ctrl.deploy( os.environ["PK_OKEx"], ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle", fantom_ctrl, fantom_ctrl.w3.toChecksumAddress(LINK_ADDR)) print("Oracle: " + oracle_addr) # 0x2ab0D4e6b968844B55a20200e8Fc3Dd6dAa29998 solidity_ctrl = SolidityController("v0.4.24") solidity_ctrl.compile(ROOT_DIR + "/contracts/OracleConsumer/") test_addr = solidity_ctrl.deploy( os.environ["PK_OKEx"], ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer", fantom_ctrl, fantom_ctrl.w3.toChecksumAddress(LINK_ADDR)) print("Test: " + test_addr) # 0xd897A7BEDa1b5f3c1CC54F518202Ce902C8a12e0 solidity_ctrl = SolidityController("v0.8.1") solidity_ctrl.compile(ROOT_DIR + "/contracts/WrappedLinkToken") link_contract = solidity_ctrl.getContract( ROOT_DIR + "/contracts/WrappedLinkToken/LinkToken.sol:ChainLink") fantom_ctrl.call(os.environ["PK_OKEx"], link_contract["abi"], fantom_ctrl.w3.toChecksumAddress(LINK_ADDR), "balanceOf", OWNER_ADDR) fantom_ctrl.send(os.environ["PK_OKEx"], link_contract["abi"], fantom_ctrl.w3.toChecksumAddress(LINK_ADDR), "transfer", test_addr, 1 * (10**18)) fantom_ctrl.call(os.environ["PK_OKEx"], link_contract["abi"], fantom_ctrl.w3.toChecksumAddress(LINK_ADDR), "balanceOf", test_addr) fantom_ctrl.call(os.environ["PK_OKEx"], link_contract["abi"], fantom_ctrl.w3.toChecksumAddress(LINK_ADDR), "balanceOf", OWNER_ADDR)
class Test_OKExChainlinkIntegration(unittest.TestCase): GAS = 152625 GWEI = 1 @classmethod def setUpClass(self) -> None: log.debug("Setup") self.okexchain_controller = OKExController() self.okexchain_controller.create_network("integration-tests") self.postgres_controller = PostgresController() self.postgres_controller.docker_run("chainlink_postgres") time.sleep(5) self.postgres_controller.init_db("chainlink") self.solidity_controller = SolidityController("v0.4.11") self.solidity_controller.compile(ROOT_DIR + "/contracts/LinkToken") self.link_address = self.solidity_controller.deploy( os.environ["PK_OKEx"], ROOT_DIR + "/contracts/LinkToken/LinkToken.sol:LinkToken", self.okexchain_controller) self.link_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/LinkToken/LinkToken.sol:LinkToken") print("LINK: " + self.link_address) self.chainlink_controller = ChainlinkController( link_address=self.link_address, eth_url="ws://18.167.77.79:8546", chain_id=65) self.chainlink_controller.docker_run("chainlink_chainlink") log.debug("\t\twait for docker startup") time.sleep(30) log.debug("/Setup") return @classmethod def tearDownClass(self) -> None: log.debug("Teardown") log.debug("\t\tstop chainlink") self.chainlink_controller.docker_stop("chainlink_chainlink") self.chainlink_controller.docker_rm("chainlink_chainlink") log.debug("\t\tstop postgres") self.chainlink_controller.docker_stop("chainlink_postgres") self.chainlink_controller.docker_rm("chainlink_postgres") log.debug("/Teardown") def test_integrate_okex(self): log.debug("test_compile_contracts") log.debug("\t\tinstall solc 0.4.24") self.solidity_controller = SolidityController("v0.4.24") self.solidity_controller.compile(ROOT_DIR + "/contracts/Oracle") oracle_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle") oracle_address = self.solidity_controller.deploy( os.environ["PK_OKEx"], ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle", self.okexchain_controller, self.link_address) print("Oracle: " + oracle_address) self.solidity_controller.compile(ROOT_DIR + "/contracts/OracleConsumer") time.sleep(10) api_address = self.solidity_controller.deploy( os.environ["PK_OKEx"], ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer", self.okexchain_controller, self.link_address) print("TEST API: " + api_address) time.sleep(10) self.okexchain_controller.send(os.environ["PK_OKEx"], self.link_contract["abi"], self.link_address, "transfer", self.GAS, api_address, 2 * (10**18)) api_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer") time.sleep(10) chainlink_address = self.chainlink_controller.get_chainlink_address(0) self.okexchain_controller.sendToken(os.environ["PK_OKEx"], (2 * (10**18)), chainlink_address, gas=self.GAS) time.sleep(10) chainlink_address = self.chainlink_controller.get_chainlink_address(1) self.okexchain_controller.sendToken(os.environ["PK_OKEx"], (2 * (10**18)), chainlink_address, gas=self.GAS) chainlink_address = self.chainlink_controller.get_chainlink_address(0) time.sleep(10) self.okexchain_controller.send(os.environ["PK_OKEx"], self.link_contract["abi"], self.link_address, "transfer", self.GAS, chainlink_address, 2 * (10**18)) time.sleep(10) self.okexchain_controller.send(os.environ["PK_OKEx"], oracle_contract["abi"], oracle_address, "setFulfillmentPermission", self.GAS, chainlink_address, True) time.sleep(10) chainlink_job_id = self.chainlink_controller.init_job(oracle_address) print("jobid: " + chainlink_job_id) time.sleep(30) self.okexchain_controller.send( os.environ["PK_OKEx"], api_contract["abi"], api_address, "requestEthereumPrice", self.GAS, self.okexchain_controller.w3.toChecksumAddress(oracle_address), chainlink_job_id) time.sleep(30) result = self.okexchain_controller.call(os.environ["PK_OKEx"], api_contract["abi"], api_address, "currentPrice") self.assertTrue(int(result) > 0)
class Test_FantomChainlinkIntegration(unittest.TestCase): @classmethod def setUpClass(self) -> None: log.debug("Setup") log.debug("\t\tblockchain docker") self.fantom_controller = FantomController() self.fantom_controller.create_network("integration-tests") self.fantom_controller.docker_build() self.fantom_controller.docker_run("fantom_lachesis") self.postgres_controller = PostgresController() self.postgres_controller.docker_run("chainlink_postgres") time.sleep(5) self.postgres_controller.init_db("chainlink") self.solidity_controller = SolidityController("v0.4.11") self.solidity_controller.compile(ROOT_DIR + "/contracts/LinkToken") self.link_address = self.solidity_controller.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/LinkToken/LinkToken.sol:LinkToken", self.fantom_controller) self.link_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/LinkToken/LinkToken.sol:LinkToken") print("LINK: " + self.link_address) self.chainlink_controller = ChainlinkController( link_address=self.link_address) self.chainlink_controller.docker_run("chainlink_chainlink") log.debug("\t\twait for docker startup") time.sleep(30) log.debug("/Setup") @classmethod def tearDownClass(self) -> None: log.debug("Teardown") log.debug("\t\tstop blockchain") self.fantom_controller.docker_stop("fantom_lachesis") self.fantom_controller.docker_rm("fantom_lachesis") self.fantom_controller.docker_rmi() log.debug("\t\tstop chainlink") self.chainlink_controller.docker_stop("chainlink_chainlink") self.chainlink_controller.docker_rm("chainlink_chainlink") log.debug("\t\tstop postgres") self.chainlink_controller.docker_stop("chainlink_postgres") self.chainlink_controller.docker_rm("chainlink_postgres") log.debug("/Teardown") def test_compile_contracts(self): log.debug("test_compile_contracts") log.debug("\t\tinstall solc 0.4.24") self.solidity_controller = SolidityController("v0.4.24") self.solidity_controller.compile(ROOT_DIR + "/contracts/Oracle") oracle_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle") oracle_address = self.solidity_controller.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/Oracle/Oracle.sol:Oracle", self.fantom_controller, self.link_address) print("Oracle: " + oracle_address) self.solidity_controller.compile(ROOT_DIR + "/contracts/OracleConsumer") api_address = self.solidity_controller.deploy( os.environ["PK_FTM"], ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer", self.fantom_controller, self.link_address) print("TEST API: " + api_address) self.fantom_controller.send(os.environ["PK_FTM"], self.link_contract["abi"], self.link_address, "transfer", 7000000, api_address, 100 * (10**18)) api_contract = self.solidity_controller.getContract( ROOT_DIR + "/contracts/OracleConsumer/APITestConsumer.sol:APITestConsumer") time.sleep(10) chainlink_address = self.chainlink_controller.get_chainlink_address(0) self.fantom_controller.sendToken(os.environ["PK_FTM"], (100 * (10**18)), chainlink_address) chainlink_address = self.chainlink_controller.get_chainlink_address(1) self.fantom_controller.sendToken(os.environ["PK_FTM"], (100 * (10**18)), chainlink_address) chainlink_address = self.chainlink_controller.get_chainlink_address(0) self.fantom_controller.send(os.environ["PK_FTM"], self.link_contract["abi"], self.link_address, "transfer", 7000000, chainlink_address, 100 * (10**18)) self.fantom_controller.send(os.environ["PK_FTM"], oracle_contract["abi"], oracle_address, "setFulfillmentPermission", 7000000, chainlink_address, True) time.sleep(10) chainlink_job_id = self.chainlink_controller.init_job(oracle_address) print("jobid: " + chainlink_job_id) time.sleep(30) self.fantom_controller.send( os.environ["PK_FTM"], api_contract["abi"], api_address, "requestEthereumPrice", 7000000, self.fantom_controller.w3.toChecksumAddress(oracle_address), chainlink_job_id) time.sleep(30) result = self.fantom_controller.call(os.environ["PK_FTM"], api_contract["abi"], api_address, "currentPrice") self.assertTrue(int(result) > 0)