Skip to content

Commit

Permalink
Merge pull request #271 from yusufidimaina9989/master
Browse files Browse the repository at this point in the history
Add Modular Exponentiation test
  • Loading branch information
zhfnjust authored Aug 30, 2023
2 parents b487c24 + a02ac29 commit 6e3a044
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/contracts/modEXP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ModExp extends SmartContract {
x = x % this.M;

if (x != 0n) {
for (let i = 0; i < this.M; i ++) {
for (let i = 0; i < 3; i ++) {
if (y >= 0n) {
// If y is odd, multiply x with result
if (y % 2n) res = (res * x) % this.M;
Expand All @@ -40,4 +40,4 @@ export class ModExp extends SmartContract {
public main(x : bigint, y : bigint, z : bigint) {
assert(z == this.modExp(x, y));
}
}
}
29 changes: 29 additions & 0 deletions tests/library.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, use } from 'chai'
import { Test } from '../src/contracts/library'
import { L } from '../src/contracts/library'
import { getDefaultSigner } from './utils/helper'
import chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)

describe('Test SmartContract `Test`', () => {
let instance: Test
let l = new L(2n, 3n)

before(async () => {
await Test.compile()
instance = new Test(2n, l)
await instance.connect(getDefaultSigner())
})

it('should pass the public method unit test successfully.', async () => {
const deployTx = await instance.deploy(1)
console.log(' Library Test contract deployed: ', deployTx.id)

const callContract = async () => {
await instance.methods.unlock(
3n
)
expect(callContract()).not.throw
}
})
})
33 changes: 33 additions & 0 deletions tests/modEXP.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, use } from 'chai'
import { MethodCallOptions} from 'scrypt-ts'
import { ModExp } from '../src/contracts/modEXP'
import { getDefaultSigner } from './utils/helper'
import chaiAsPromised from 'chai-as-promised'
import { describe } from 'mocha'

use(chaiAsPromised)

describe('Test SmartContract `modEXP`', () => {
let instance: ModExp
before(async () => {
await ModExp.compile()

instance = new ModExp(13n)
await instance.connect(getDefaultSigner())
})

it('should pass the public method unit test successfully.', async () => {
const deployTx = await instance.deploy(1)
console.log('modEXP contract deployed: ', deployTx.id)


const callContract = async () => {
await instance.methods.main(
2n,3n,8n
)
expect(callContract()).not.throw
}

})

})

0 comments on commit 6e3a044

Please sign in to comment.