Created
May 20, 2022 12:46
-
-
Save gracelungu/24b954ee5b9346a9a36b9c96985f6e64 to your computer and use it in GitHub Desktop.
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
it("Should save and retrieve the savings data", async function () { | |
// Get the signer | |
const [sender] = await ethers.getSigners(); | |
// Amount to save | |
const ethAmount = "0.001"; | |
const weiAmount = ethers.utils.parseEther(ethAmount); | |
const transaction = { | |
value: weiAmount, | |
}; | |
// Withdraw timestamp | |
const withdrawTime = Date.now() + 1000; | |
// Save the amount | |
await lockSave.save(withdrawTime, transaction); | |
// Get savings | |
const savings = await lockSave.getSavings(); | |
// Extract savings values | |
const saving = savings.values().next().value; | |
const [owner, value, timestamp, withdrawTimestamp] = saving; | |
const currentSaving: Saving = { | |
address: sender.address, | |
value: weiAmount.toString(), | |
timestamp: Date.now(), | |
withdrawTimestamp: withdrawTime, | |
}; | |
const expectedSaving: Saving = { | |
address: owner, | |
value: value.toString(), | |
timestamp: timestamp.toNumber(), | |
withdrawTimestamp: withdrawTimestamp.toNumber(), | |
}; | |
// Assert saving values | |
expect(currentSaving.address).to.equal(expectedSaving.address); | |
expect(currentSaving.value).to.equal(currentSaving.value); | |
expect( | |
currentSaving.withdrawTimestamp - expectedSaving.timestamp | |
).to.be.greaterThan(0); | |
expect(currentSaving.withdrawTimestamp).to.equal( | |
expectedSaving.withdrawTimestamp.toString() | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment