Near-One / near-plugins

Implementation of common patterns used for NEAR smart contracts.
Creative Commons Zero v1.0 Universal
27 stars 12 forks source link

Avoid duplication of test and example contracts #48

Open mooori opened 1 year ago

mooori commented 1 year ago

Description

For example for the Pausable plugin there is a basically identical Counter contract in the following locations:

Problem

This duplication makes updates very cumbersome and it carries the risk of the contracts getting out of sync.

Proposed solution

Have only one contract per plugin which is used in tests and serves as example.

For instance the contract in near-plugins/tests/contracts/access_controllable/ is compiled, deployed and interacted with by integration tests in near-plugins/tests/access_controllable.rs. This happens via cargo test and is hooked up with CI.

If this contract is polished I think we can remove the AccessControllable example in the README and instead add a link to this contract's lib.rs.

According to this pattern, contracts in near-plugins/tests/contracts/ are integrated with cargo test and CI. Therefore I would argue no additional contracts are needed in examples/**. Instead examples link to near-plugins/tests/contracts/ too.

In addition, unit tests in /near-plugins/src/*.rs can be replaced by the integration tests mentioned above.

birchmd commented 1 year ago

I'm generally in favour of reducing code duplication. The rule of thumb I think about is whether the two pieces of code will change at the same time and for the same reasons. In the case of these tests and examples I think it is true they will always change together so it makes sense to unify them in my opinion.

Please proceed with your proposed solution @mooori