-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/eddsa/twisted
- Loading branch information
Showing
7 changed files
with
168 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
UInt64, | ||
SmartContract, | ||
Mina, | ||
AccountUpdate, | ||
method, | ||
} from 'o1js'; | ||
|
||
class MyContract extends SmartContract { | ||
@method async shouldMakeCompileThrow() { | ||
this.network.blockchainLength.get(); | ||
} | ||
} | ||
|
||
let contractAccount: Mina.TestPublicKey; | ||
let contract: MyContract; | ||
let feePayer: Mina.TestPublicKey; | ||
|
||
describe('transactions', () => { | ||
beforeAll(async () => { | ||
// set up local blockchain, create contract account keys, deploy the contract | ||
let Local = await Mina.LocalBlockchain({ proofsEnabled: false }); | ||
Mina.setActiveInstance(Local); | ||
[feePayer] = Local.testAccounts; | ||
|
||
contractAccount = Mina.TestPublicKey.random(); | ||
contract = new MyContract(contractAccount); | ||
|
||
let tx = await Mina.transaction(feePayer, async () => { | ||
AccountUpdate.fundNewAccount(feePayer); | ||
await contract.deploy(); | ||
}); | ||
tx.sign([feePayer.key, contractAccount.key]).send(); | ||
}); | ||
|
||
it('setFee should not change nonce', async () => { | ||
let tx = await Mina.transaction(feePayer, async () => { | ||
contract.requireSignature(); | ||
AccountUpdate.attachToTransaction(contract.self); | ||
}); | ||
let nonce = tx.transaction.feePayer.body.nonce; | ||
let promise = await tx.sign([feePayer.key, contractAccount.key]).send(); | ||
let new_fee = await promise.setFee(new UInt64(100)); | ||
new_fee.sign([feePayer.key,contractAccount.key]); | ||
// second send is rejected for using the same nonce | ||
await expect((new_fee.send())) | ||
.rejects | ||
.toThrowError("Account_nonce_precondition_unsatisfied"); | ||
// check that tx was applied, by checking nonce was incremented | ||
expect(new_fee.transaction.feePayer.body.nonce).toEqual(nonce); | ||
}); | ||
|
||
it('Second tx should work when first not sent', async () => { | ||
let tx = await Mina.transaction(feePayer, async () => { | ||
contract.requireSignature(); | ||
AccountUpdate.attachToTransaction(contract.self); | ||
}); | ||
let nonce = tx.transaction.feePayer.body.nonce; | ||
let promise = tx.sign([feePayer.key, contractAccount.key]); | ||
let new_fee = promise.setFeePerSnarkCost(42.7); | ||
await new_fee.sign([feePayer.key,contractAccount.key]); | ||
await new_fee.send(); | ||
// check that tx was applied, by checking nonce was incremented | ||
expect((await new_fee).transaction.feePayer.body.nonce).toEqual(nonce); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters