Skip to content

Commit

Permalink
agent: fix tests
Browse files Browse the repository at this point in the history
`isValidSignature` was calling the `bytes` version due to overloading
issue with Truffle.
  • Loading branch information
ßingen committed Jun 17, 2020
1 parent 7d6ee71 commit 3f21609
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
10 changes: 10 additions & 0 deletions apps/agent/contracts/test/mocks/AgentMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "../../Agent.sol";


contract AgentMock is Agent {
function isValidSignatureBytes32(bytes32 _hash, bytes memory _signature) public view returns (bytes4) {
return isValidSignature(_hash, _signature);
}
}
2 changes: 1 addition & 1 deletion apps/agent/test/agent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const runSharedAgentTests = require('./agent_shared.js')

contract('Agent', (accounts) => {
runSharedAgentTests('Agent', { accounts, artifacts, web3 })
runSharedAgentTests('AgentMock', { accounts, artifacts, web3 })
})
36 changes: 18 additions & 18 deletions apps/agent/test/agent_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,18 +770,18 @@ module.exports = (
})

it('isValidSignature returns false if there is not designated signer and hash isn\'t presigned', async () => {
assertIsValidSignature(false, await agent.isValidSignature(HASH, NO_SIG))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, NO_SIG))
})

it('presigns a hash', async () => {
await agent.presignHash(HASH, { from: presigner })

assertIsValidSignature(true, await agent.isValidSignature(HASH, NO_SIG))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, NO_SIG))
})

it('fails to presign a hash if not authorized', async () => {
await assertRevert(agent.presignHash(HASH, { from: nobody }), errors.APP_AUTH_FAILED)
assertIsValidSignature(false, await agent.isValidSignature(HASH, NO_SIG))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, NO_SIG))
})

context('> Designated signer', () => {
Expand Down Expand Up @@ -876,27 +876,27 @@ module.exports = (

it('isValidSignature returns true to a valid signature', async () => {
const signature = await sign(HASH, signerOrKey)
assertIsValidSignature(true, await agent.isValidSignature(HASH, signature))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, signature))
})

it('isValidSignature returns true to a valid signature with legacy version', async () => {
const legacyVersionSignature = await sign(HASH, signerOrKey, true)
assertIsValidSignature(true, await agent.isValidSignature(HASH, legacyVersionSignature))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, legacyVersionSignature))
})

it('isValidSignature returns false to an invalid signature', async () => {
const badSignature = (await sign(HASH, signerOrKey)).slice(0, -2) // drop last byte
assertIsValidSignature(false, await agent.isValidSignature(HASH, badSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, badSignature))
})

it('isValidSignature returns false to a signature with an invalid v', async () => {
const invalidVersionSignature = await sign(HASH, signerOrKey, false, true)
assertIsValidSignature(false, await agent.isValidSignature(HASH, invalidVersionSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, invalidVersionSignature))
})

it('isValidSignature returns false to an unauthorized signer', async () => {
const otherSignature = await sign(HASH, notSignerOrKey)
assertIsValidSignature(false, await agent.isValidSignature(HASH, otherSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, otherSignature))
})
})
}
Expand All @@ -916,7 +916,7 @@ module.exports = (
// false - doesn't modify state on checking sig
await setDesignatedSignerContract(true, true, false, false)

assertIsValidSignature(true, await agent.isValidSignature(HASH, ERC1271_SIG))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, ERC1271_SIG))
})

it('isValidSignature returns false if designated signer returns false', async () => {
Expand All @@ -927,7 +927,7 @@ module.exports = (
await setDesignatedSignerContract(true, false, false, false)

// Signature fails check
assertIsValidSignature(false, await agent.isValidSignature(HASH, ERC1271_SIG))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, ERC1271_SIG))
})

it('isValidSignature returns true even if the designated signer doesnt support the interface', async () => {
Expand All @@ -937,7 +937,7 @@ module.exports = (
// false - doesn't modify state on checking sig
await setDesignatedSignerContract(false, true, false, false)

assertIsValidSignature(true, await agent.isValidSignature(HASH, ERC1271_SIG))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, ERC1271_SIG))
})

it('isValidSignature returns false if designated signer reverts', async () => {
Expand All @@ -948,7 +948,7 @@ module.exports = (
await setDesignatedSignerContract(true, true, true, false)

// Reverts on checking
assertIsValidSignature(false, await agent.isValidSignature(HASH, ERC1271_SIG))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, ERC1271_SIG))
})

it('isValidSignature returns false if designated signer attempts to modify state', async () => {
Expand All @@ -959,7 +959,7 @@ module.exports = (
await setDesignatedSignerContract(true, true, false, true)

// Checking costs too much gas
assertIsValidSignature(false, await agent.isValidSignature(HASH, ERC1271_SIG))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, ERC1271_SIG))
})
})

Expand All @@ -972,26 +972,26 @@ module.exports = (

it('isValidSignature returns false to an empty signature', async () => {
const emptySig = '0x'
assertIsValidSignature(false, await agent.isValidSignature(HASH, emptySig))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, emptySig))
})

it('isValidSignature returns false to an invalid mode signature', async () => {
const invalidSignature = SIGNATURE_MODES.Invalid
assertIsValidSignature(false, await agent.isValidSignature(HASH, invalidSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, invalidSignature))
})

it('isValidSignature returns false to an unspecified mode signature', async () => {
const unspecifiedSignature = SIGNATURE_MODES.NMode
assertIsValidSignature(false, await agent.isValidSignature(HASH, unspecifiedSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, unspecifiedSignature))
})

it('isValidSignature returns true to an invalid signature iff the hash was presigned', async () => {
const invalidSignature = SIGNATURE_MODES.Invalid
assertIsValidSignature(false, await agent.isValidSignature(HASH, invalidSignature))
assertIsValidSignature(false, await agent.isValidSignatureBytes32(HASH, invalidSignature))

// Now presign it
await agent.presignHash(HASH, { from: presigner })
assertIsValidSignature(true, await agent.isValidSignature(HASH, invalidSignature))
assertIsValidSignature(true, await agent.isValidSignatureBytes32(HASH, invalidSignature))
})
})

Expand Down

0 comments on commit 3f21609

Please sign in to comment.