-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { expect } from "chai"; | ||
import Constructors from "../typed_contracts/multisig/constructors/multisig"; | ||
import ContractAbi from "../artifacts/multisig/multisig.json"; | ||
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; | ||
import { | ||
assignKeyringPairs, | ||
buildTransaction, | ||
proposeTransaction, | ||
} from "./utils/testHelpers"; | ||
import { MessageIndex } from "./utils/MessageIndex"; | ||
import Contract from "../typed_contracts/multisig/contracts/multisig"; | ||
|
||
let api; | ||
let keyring; | ||
let keypairs; | ||
let aliceKeyringPair; | ||
let bobKeyringPair; | ||
let multisigMessageIndex; | ||
|
||
before(async () => { | ||
try { | ||
// Perform async operations to obtain the api instance | ||
const wsProvider = new WsProvider("ws://127.0.0.1:9944"); | ||
|
||
api = await ApiPromise.create({ provider: wsProvider }); | ||
|
||
if (!wsProvider.isConnected) { | ||
throw new Error("Unable to connect to WebSocket"); | ||
} | ||
|
||
// Create a keyring instance | ||
keyring = new Keyring({ type: "sr25519" }); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); // Terminate the execution | ||
} | ||
}); | ||
|
||
after(() => { | ||
// Disconnect from the API on completion | ||
api.disconnect(); | ||
}); | ||
|
||
describe("TxId Test", () => { | ||
before(() => { | ||
// call function to create keyring pairs | ||
keypairs = assignKeyringPairs(keyring, 2); | ||
[aliceKeyringPair, bobKeyringPair] = keypairs; | ||
}); | ||
|
||
it.only("TxId should increment", async () => { | ||
multisigMessageIndex = new MessageIndex(ContractAbi); | ||
|
||
// Initial args | ||
const init_threshold = 1; | ||
|
||
// Create a new contract | ||
const constructors = new Constructors(api, aliceKeyringPair); | ||
|
||
const { address } = await constructors.new(init_threshold, [ | ||
aliceKeyringPair.address, | ||
]); | ||
|
||
// Assert that the contract was created | ||
expect(address).to.exist; | ||
|
||
// Bind the contract to the new address | ||
const multisig = new Contract(address, aliceKeyringPair, api); | ||
|
||
const addOwnerTx = await buildTransaction( | ||
api, | ||
address, | ||
"add_owner", | ||
[bobKeyringPair.address], | ||
multisigMessageIndex | ||
); | ||
|
||
// Propose the transaction on chain | ||
await proposeTransaction(multisig, addOwnerTx, 0); | ||
|
||
// Propose the same transaction on chain | ||
await proposeTransaction(multisig, addOwnerTx, 1); | ||
|
||
// Check that the txId has been incremented | ||
const nextTxId = (await multisig.query.getNextTxId()).value.unwrap().toNumber(); | ||
expect(nextTxId).to.equal(2); | ||
}); | ||
}); |
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
Large diffs are not rendered by default.
Oops, something went wrong.