Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e tests #62

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Add e2e tests #62

wants to merge 12 commits into from

Conversation

ThunderDeliverer
Copy link
Contributor

@ThunderDeliverer ThunderDeliverer commented Sep 28, 2021

Add end-to-end tests

This branch introduces tests to the predeployed contracts and migrates from Truffle to Waffle.

The changes are separated in branches:

  • Migrate from Truffle to Waffle
    • Includes addition of packages and small configuration changes
  • Add Token test
    • Test suite to test the token contracts
  • Add DEX test
    • Test suite to test the DEX contract
  • Add Oracle test
    • Test suite to test the oracle contract
  • Add Schedule test
    • Test suite to test the schedule contract
  • Add StateRent test
    • Test suite to test the state rent contract

NOTE: I'll keep this in draft until the suite is ready.

Removed Truffle from the project, since it was not being used, and added
Waffle testing framework and the required configuration to the project.
solc dependency had to be explicitly added in order to support version
^0.8.0, as the highest linked version in Waffle is ^0.6.0.
Added tests to test the operation of Tokens.
@xlc xlc requested a review from zjb0807 September 28, 2021 02:00
@zjb0807
Copy link
Member

zjb0807 commented Sep 28, 2021

Maybe it would be better to put all e2e tests here. @xlc
AcalaNetwork/Acala#1437

@xlc
Copy link
Member

xlc commented Sep 28, 2021

yeah I think it make sense to have this merged with the one in Acala main repo.

Added tests to verify the correct DEX operation.
Added tests to verify the expected operation of Oracle.
@ThunderDeliverer
Copy link
Contributor Author

Sure, I'll merge it (through a new PR) once I'm done with the tests. Should be tomorrow.

Added tests to test the expected operation of Schedule.
Comment on lines 182 to 205
it("emits RescheduledCall event when rescheduling a call and executes it at a new time", async () => {
const call = await dex.populateTransaction.swapWithExactSupply([ADDRESS.DOT, ADDRESS.AUSD], 200, 1);
const first_target_block_number = Number(await provider.api.query.system.number()) + 5;
const second_target_block_number = Number(await provider.api.query.system.number()) + 10;
let iface = new ethers.utils.Interface(SCHEDULE_ABI);

let current_block_number = Number(await provider.api.query.system.number());
await schedule.scheduleCall(ADDRESS.DOT, 0, 300000, 10000, 5, ethers.utils.hexlify(call.data as string));

let block_hash = await provider.api.query.system.blockHash(current_block_number);
const data = await provider.api.derive.tx.events(block_hash);
let event = data.events.filter(item => item.event.data.some(data => data.address == ADDRESS.Schedule && data.topics[0] == iface.getEventTopic(iface.getEvent("ScheduledCall"))));

if (event.length > 0) {
let log = {
topics: [event[0].event.data[0].topics[0].toString(), event[0].event.data[0].topics[1].toString(), event[0].event.data[0].topics[2].toString()], data: event[0].event.data[0].data.toString()
};
let decode_log = await iface.parseLog(log);
await expect(schedule.rescheduleCall(7, ethers.utils.hexlify(decode_log.args.task_id)))
.to.emit(schedule, "RescheduledCall")
.withArgs(await wallet.getAddress(), ethers.utils.hexlify(decode_log.args.task_id));
} else {
expect(false).to.be.ok;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xlc @zjb0807 I could use another set of eyes on this one. For some reason, the event ScheduledCall is never emitted and without it, I can't test the reschedule call. I went over this setup a couple of times and can't find the issue. This should pass and the setup is done in the same way as in previous examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it, you can refer to it to modify others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was one additional one. I updated it in a same manner you fixed this example. Thank you! 🙏

ThunderDeliverer and others added 3 commits October 1, 2021 02:18
Added tests to validate the expected operation of StateRent.
Cleaned up the tests and modified the remaining Schedule example to the
new way of retrieving the events.
@ThunderDeliverer
Copy link
Contributor Author

ThunderDeliverer commented Oct 4, 2021

Maybe it would be better to put all e2e tests here. @xlc AcalaNetwork/Acala#1437

I've been thinking about this. Maybe it would make sense to add these tests to both repositories? We have them and it's good to use them wherever we can. What do you to think @xlc and @zjb0807 ?

Actually the more I think about it, the more sense it makes for the tests to be here. They will be added to AcalaNetwork/Acala repository once the reference to this repository gets updated.

@xlc
Copy link
Member

xlc commented Oct 4, 2021

We need the tests in Acala repo so it can be ran by CI

@ThunderDeliverer
Copy link
Contributor Author

I could open up a PR to add the tests contained in the predeploy-contracts repository to the CI in Acala:

.PHONY: test-predeployed
test-predeployed:
	cargo build --features with-mandala-runtime
	cd predeploy-contracts && yarn && yarn build && yarn test

@xlc
Copy link
Member

xlc commented Oct 4, 2021

I am ok to have this merged and then we can see if we want to improve the workflow.

@ThunderDeliverer ThunderDeliverer marked this pull request as ready for review October 5, 2021 20:51
@ferrell-code ferrell-code mentioned this pull request Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants