Skip to content

Commit

Permalink
Fix expect throw
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfnjust committed Aug 29, 2023
1 parent 04957fb commit 74e69c4
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"plugin:@typescript-eslint/recommended"
],
"rules": {
"prefer-rest-params": "off" // super(...arguments)
"prefer-rest-params": "off", // super(...arguments)
"@typescript-eslint/no-inferrable-types": "off"
}
}
2 changes: 1 addition & 1 deletion tests/crossChainSwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Test SmartContract `CrossChainSwap`', () => {
pubKeyOrAddrToSign: bobPubKey,
} as MethodCallOptions<CrossChainSwap>
)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/locktime has not yet expired/
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/crowdfund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ describe('Test SmartContract `Crowdfund`', () => {
} as MethodCallOptions<Crowdfund>
)

expect(callContract()).to.be.rejectedWith(/fundraising expired/)
return expect(callContract()).to.be.rejectedWith(/fundraising expired/)
})
})
4 changes: 2 additions & 2 deletions tests/demo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ describe('Test SmartContract `Demo`', () => {
it('should throw when calling `add`', async () => {
await demo.deploy(1)
const callContract = async () => await demo.methods.add(-5n)
expect(callContract()).to.be.rejectedWith(/add check failed/)
return expect(callContract()).to.be.rejectedWith(/add check failed/)
})

it('should throw when calling `sub`', async () => {
await demo.deploy(1)
const callContract = async () => await demo.methods.sub(9n)
expect(callContract()).to.be.rejectedWith(/sub check failed/)
return expect(callContract()).to.be.rejectedWith(/sub check failed/)
})
})
2 changes: 1 addition & 1 deletion tests/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe('Test SmartContract `ERC20`', () => {
150n
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/Execution failed, ERC20: insufficient allowance/
)
})
Expand Down
6 changes: 3 additions & 3 deletions tests/erc721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Test SmartContract `Erc721`', () => {
() => getDummySig() // mint without correct minter sig
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/minter signature check failed/
)
})
Expand All @@ -60,7 +60,7 @@ describe('Test SmartContract `Erc721`', () => {
(sigResps) => findSig(sigResps, myPublicKey) // minterSig
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/token was already minted before/
)
})
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Test SmartContract `Erc721`', () => {
} as MethodCallOptions<Erc721>
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/sender doesn't have the token/
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/hashedMapNonState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Test SmartContract `HashedMapNonState`', () => {
await hashedMapNonState.deploy(1)
const callContract = async () =>
await hashedMapNonState.methods.delete(2n)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/hashedMap should have the key before delete/
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/hashedSetNonState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Test SmartContract `HashedSetNonState`', () => {
await hashedSetNonState.deploy(1)
const callContract = async () =>
await hashedSetNonState.methods.delete(2n)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/hashedSet should have the key before delete/
)
})
Expand Down
4 changes: 3 additions & 1 deletion tests/helloWorld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('Test SmartContract `HelloWorld`', () => {
await helloWorld.deploy(1)
const callContract = async () =>
await helloWorld.methods.unlock(toByteString('wrong message', true))
expect(callContract()).to.be.rejectedWith(/Not expected message!/)
return expect(callContract()).to.be.rejectedWith(
/Not expected message!/
)
})
})
2 changes: 1 addition & 1 deletion tests/multiPartyHashPuzzle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ describe('Test SmartContract `MultiPartyHashPuzzle`', () => {
preimagesWrong[0] = sha256('aabbcc')
const callContract = async () =>
await instance.methods.unlock(preimagesWrong)
expect(callContract()).to.be.rejectedWith(/hash mismatch/)
return expect(callContract()).to.be.rejectedWith(/hash mismatch/)
})
})
2 changes: 1 addition & 1 deletion tests/multiPartyHashPuzzleOpt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ describe('Test SmartContract `MultiPartyHashPuzzleOpt`', () => {
preimagesWrong[0] = sha256('aabbcc')
const callContract = async () =>
await instance.methods.unlock(preimagesWrong)
expect(callContract()).to.be.rejectedWith(/hash mismatch/)
return expect(callContract()).to.be.rejectedWith(/hash mismatch/)
})
})
2 changes: 1 addition & 1 deletion tests/multiSig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ describe('Test SmartContract `P2MS`', () => {
} as MethodCallOptions<MultiSigPayment>
)

expect(callContract()).to.be.rejectedWith(/Execution failed/)
return expect(callContract()).to.be.rejectedWith(/Execution failed/)
})
})
8 changes: 5 additions & 3 deletions tests/ordinalLock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PubKey,
hash160,
ByteString,
ContractTransaction,
} from 'scrypt-ts'
import { OrdinalLock, purchaseTxBuilder } from '../src/contracts/ordinalLock'
import chaiAsPromised from 'chai-as-promised'
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('Test SmartContract `OrdinalLock`', () => {
current: OrdinalLock,
options: MethodCallOptions<OrdinalLock>,
destOutput: ByteString
): Promise<any> => {
): Promise<ContractTransaction> => {
const destOutputBR = new bsv.encoding.BufferReader(
Buffer.from(destOutput, 'hex')
)
Expand All @@ -132,6 +133,7 @@ describe('Test SmartContract `OrdinalLock`', () => {
const result = {
tx: unsignedTx,
atInputIndex: 0, // the contract input's index
nexts: [],
}

return Promise.resolve(result)
Expand All @@ -143,7 +145,7 @@ describe('Test SmartContract `OrdinalLock`', () => {
await instance.methods.purchase(destOutputStr, {
changeAddress: await buyerSigner.getDefaultAddress(),
} as MethodCallOptions<OrdinalLock>)
expect(callContract()).to.be.rejectedWith(/Execution failed/)
return expect(callContract()).to.be.rejectedWith(/Execution failed/)
})

it('should fail cancel method w bad sig.', async () => {
Expand All @@ -161,6 +163,6 @@ describe('Test SmartContract `OrdinalLock`', () => {
changeAddress: wrongKey.toAddress(),
} as MethodCallOptions<OrdinalLock>
)
expect(callContract()).to.be.rejectedWith(/bad seller/)
return expect(callContract()).to.be.rejectedWith(/bad seller/)
})
})
6 changes: 4 additions & 2 deletions tests/p2pkh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ describe('Test SmartContract `P2PKH`', () => {
} as MethodCallOptions<P2PKH>
)

expect(callContract()).to.be.rejectedWith(/signature check failed/)
return expect(callContract()).to.be.rejectedWith(
/signature check failed/
)
})

it('should fail if passing wrong public key', async () => {
Expand All @@ -90,7 +92,7 @@ describe('Test SmartContract `P2PKH`', () => {
pubKeyOrAddrToSign: myPublicKey, // use the correct private key, `myPrivateKey`, to sign
} as MethodCallOptions<P2PKH>
)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/public key hashes are not equal/
)
})
Expand Down
4 changes: 3 additions & 1 deletion tests/priceBet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ describe('Test SmartContract `PriceBet`', () => {
} as MethodCallOptions<PriceBet>
)

expect(callContract()).to.be.rejectedWith(/signature check failed/)
return expect(callContract()).to.be.rejectedWith(
/signature check failed/
)
})
})
6 changes: 3 additions & 3 deletions tests/recallable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Test SmartContract `Recallable`', () => {
pubKeyOrAddrToSign: alicePublicKey,
} as MethodCallOptions<Recallable>
)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/invalid value of `satoshisSent`/
)
})
Expand All @@ -55,7 +55,7 @@ describe('Test SmartContract `Recallable`', () => {
} as MethodCallOptions<Recallable>
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/invalid value of `satoshisSent`/
)
})
Expand All @@ -67,7 +67,7 @@ describe('Test SmartContract `Recallable`', () => {
PubKey(toHex(bobPublicKey)),
BigInt(1)
)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/user's signature check failed/
)
})
Expand Down
6 changes: 4 additions & 2 deletions tests/socialRecovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe('Test SmartContract `SocialRecovery`', () => {
pubKeyOrAddrToSign: wrongKey.toPublicKey(),
} as MethodCallOptions<SocialRecovery>
)
expect(callContract()).to.be.rejectedWith(/signature check failed/)
return expect(callContract()).to.be.rejectedWith(
/signature check failed/
)
})

it('should pass updating signing key when threshold reached.', async () => {
Expand Down Expand Up @@ -142,7 +144,7 @@ describe('Test SmartContract `SocialRecovery`', () => {
} as MethodCallOptions<SocialRecovery>
)

expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/Guardian threshold not reached/
)
})
Expand Down
6 changes: 4 additions & 2 deletions tests/statefulMultiSig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ describe('Test SmartContract `StatefulMultiSig`', () => {
},
} as MethodCallOptions<StatefulMultiSig>
)
expect(callContract()).to.be.rejectedWith(/signature check failed/)
return expect(callContract()).to.be.rejectedWith(
/signature check failed/
)
})

it('should fail pay if threshold not reached', async () => {
Expand All @@ -157,7 +159,7 @@ describe('Test SmartContract `StatefulMultiSig`', () => {
await statefulMultiSig.signer.getDefaultAddress(),
} as MethodCallOptions<StatefulMultiSig>
)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/Not enough valid signatures./
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/timeLock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Test SmartContract `TimeLock`', () => {
await timeLock.methods.unlock({
lockTime: 1673500100,
} as MethodCallOptions<TimeLock>)
expect(callContract()).to.be.rejectedWith(
return expect(callContract()).to.be.rejectedWith(
/locktime has not yet expired/
)
})
Expand Down

0 comments on commit 74e69c4

Please sign in to comment.