Skip to content

Commit

Permalink
Fix tests to match the new ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 18, 2024
1 parent c2f18a9 commit 220897d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ ape compile

```shell
poetry shell
ape test
# TODO: there is a bug in pytest/ape test that it does not find the tests
# unless you explicitly pass it the tests folder
ape test tests
```

## Deploying
Expand Down
12 changes: 10 additions & 2 deletions src/TermsOfService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ITermsOfService {
*/
contract TermsOfService is Ownable, ITermsOfService {

// OpenZeppelin lib supporting smart contract based signing as opposite to EOA signing
using SignatureChecker for address;

// Terms of service acceptances
Expand All @@ -37,19 +38,26 @@ contract TermsOfService is Ownable, ITermsOfService {
//
// Published terms of services
//
//
// Terms of service versions, starting from 1 and
// increased with one for the each iteration.
//
mapping(uint16 version => bytes32 acceptanceMessageHash) public versions;

//
// What is the hash of currently active terms of service version
//
bytes32 public latestAcceptanceMessageHash;

//
// Terms of service versions, starting from 1 and
// increased with one for the each iteration.
// What is the version numbe of current terms of service version
//
uint16 public latestTermsOfServiceVersion;

// Add a new terms of service version
event UpdateTermsOfService(uint16 version, bytes32 acceptanceMessageHash, string acceptanceMessage);

// User accepted a specific terms of service version
event Signed(address signer, uint16 version, bytes32 hash, bytes metadata);

constructor() Ownable() {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_sign_terms_of_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_not_signed(
):
new_version = 1
new_hash = random.randbytes(32)
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)

assert not tos.hasAcceptedHash(random_user, new_hash)
assert not tos.hasAcceptedVersion(random_user, 1)
Expand All @@ -56,7 +56,7 @@ def test_signed(
)
new_hash = get_signing_hash(signing_content)

tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, signing_content, sender=deployer)

assert not tos.hasAcceptedHash(random_user, new_hash)
assert not tos.hasAcceptedVersion(random_user, 1)
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_sign_twice(
)
new_hash = get_signing_hash(signing_content)

tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, signing_content, sender=deployer)

signature = random_user.sign_message(signing_content).encode_rsv()

Expand All @@ -120,7 +120,7 @@ def test_sign_no_version(
)
new_hash = get_signing_hash(signing_content)

tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, signing_content, sender=deployer)

signature = random_user.sign_message(signing_content).encode_rsv()

Expand All @@ -144,7 +144,7 @@ def test_sign_wrong_signature(
)
new_hash = get_signing_hash(signing_content)

tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, signing_content, sender=deployer)

with reverts("Signature is not valid"):
tos.signTermsOfServiceOwn(new_hash, random.randbytes(32), b"", sender=random_user)
14 changes: 7 additions & 7 deletions tests/test_update_terms_of_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_start_zero_version(tos: ContractInstance):
def test_first_terms_of_service(tos: ContractInstance, deployer: TestAccount):
new_version = 1
new_hash = random.randbytes(32)
tx = tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tx = tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)
assert tos.latestTermsOfServiceVersion() == 1
assert tos.latestAcceptanceMessageHash() == new_hash

Expand All @@ -48,13 +48,13 @@ def test_first_terms_of_service(tos: ContractInstance, deployer: TestAccount):
def test_second_terms_of_service(tos: ContractInstance, deployer: TestAccount):
new_version = 1
new_hash = random.randbytes(32)
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)
assert tos.latestTermsOfServiceVersion() == 1
assert tos.latestAcceptanceMessageHash() == new_hash

new_version = 2
new_hash = random.randbytes(32)
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)
assert tos.latestTermsOfServiceVersion() == 2
assert tos.latestAcceptanceMessageHash() == new_hash

Expand All @@ -64,7 +64,7 @@ def test_wrong_owner(tos: ContractInstance, random_user: TestAccount):
new_hash = random.randbytes(32)

with pytest.raises(ContractLogicError):
tos.updateTermsOfService(new_version, new_hash, sender=random_user)
tos.updateTermsOfService(new_version, new_hash, "", sender=random_user)

assert tos.latestTermsOfServiceVersion() == 0

Expand All @@ -74,19 +74,19 @@ def test_wrong_version(tos: ContractInstance, deployer: TestAccount):
new_hash = random.randbytes(32)

with pytest.raises(ContractLogicError):
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)

assert tos.latestTermsOfServiceVersion() == 0


def test_hash_reuse(tos: ContractInstance, deployer: TestAccount):
new_version = 1
new_hash = random.randbytes(32)
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)

new_version = 2
with pytest.raises(ContractLogicError):
tos.updateTermsOfService(new_version, new_hash, sender=deployer)
tos.updateTermsOfService(new_version, new_hash, "", sender=deployer)


def test_transfer_ownership(tos: ContractInstance, deployer: TestAccount, random_user: TestAccount):
Expand Down

0 comments on commit 220897d

Please sign in to comment.