mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-02-06 11:44:16 +00:00
Make amount of stake configurable
This commit is contained in:
parent
8736e5a1aa
commit
d49c75a74b
@ -7,7 +7,11 @@ import "./Stakes.sol";
|
|||||||
|
|
||||||
contract Storage is Contracts, Proofs, Stakes {
|
contract Storage is Contracts, Proofs, Stakes {
|
||||||
|
|
||||||
constructor(IERC20 token) Stakes(token) {}
|
uint private stakeAmount;
|
||||||
|
|
||||||
|
constructor(IERC20 token, uint _stakeAmount) Stakes(token) {
|
||||||
|
stakeAmount = _stakeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
function newContract(
|
function newContract(
|
||||||
uint _duration,
|
uint _duration,
|
||||||
@ -24,7 +28,7 @@ contract Storage is Contracts, Proofs, Stakes {
|
|||||||
)
|
)
|
||||||
public
|
public
|
||||||
{
|
{
|
||||||
require(_stake(_host) > 0, "Insufficient stake");
|
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
||||||
bytes32 id = _newContract(
|
bytes32 id = _newContract(
|
||||||
_duration,
|
_duration,
|
||||||
_size,
|
_size,
|
||||||
|
@ -5,6 +5,7 @@ const { exampleRequest, exampleBid } = require("./examples")
|
|||||||
|
|
||||||
describe("Storage", function () {
|
describe("Storage", function () {
|
||||||
|
|
||||||
|
const stakeAmount = 100
|
||||||
const request = exampleRequest()
|
const request = exampleRequest()
|
||||||
const bid = exampleBid()
|
const bid = exampleBid()
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ describe("Storage", function () {
|
|||||||
let Token = await ethers.getContractFactory("TestToken")
|
let Token = await ethers.getContractFactory("TestToken")
|
||||||
let StorageContracts = await ethers.getContractFactory("Storage")
|
let StorageContracts = await ethers.getContractFactory("Storage")
|
||||||
token = await Token.connect(host).deploy()
|
token = await Token.connect(host).deploy()
|
||||||
storage = await StorageContracts.deploy(token.address)
|
storage = await StorageContracts.deploy(token.address, stakeAmount)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("creating a new storage contract", function () {
|
describe("creating a new storage contract", function () {
|
||||||
@ -25,8 +26,8 @@ describe("Storage", function () {
|
|||||||
let id
|
let id
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await token.approve(storage.address, 20)
|
await token.approve(storage.address, stakeAmount)
|
||||||
await storage.connect(host).increaseStake(20)
|
await storage.connect(host).increaseStake(stakeAmount)
|
||||||
let requestHash = hashRequest(request)
|
let requestHash = hashRequest(request)
|
||||||
let bidHash = hashBid({...bid, requestHash})
|
let bidHash = hashBid({...bid, requestHash})
|
||||||
await storage.newContract(
|
await storage.newContract(
|
||||||
@ -60,6 +61,8 @@ describe("Storage", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("doesn't create contract when insufficient stake", async function () {
|
it("doesn't create contract when insufficient stake", async function () {
|
||||||
|
await token.approve(storage.address, stakeAmount - 1)
|
||||||
|
await storage.connect(host).increaseStake(stakeAmount - 1)
|
||||||
let requestHash = hashRequest(request)
|
let requestHash = hashRequest(request)
|
||||||
let bidHash = hashBid({...bid, requestHash})
|
let bidHash = hashBid({...bid, requestHash})
|
||||||
await expect(storage.newContract(
|
await expect(storage.newContract(
|
||||||
@ -78,7 +81,6 @@ describe("Storage", function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: configurable amount of stake
|
|
||||||
// TODO: lock up stake when new contract
|
// TODO: lock up stake when new contract
|
||||||
// TODO: unlock stake at end of contract
|
// TODO: unlock stake at end of contract
|
||||||
// TODO: payment when new contract
|
// TODO: payment when new contract
|
||||||
|
Loading…
x
Reference in New Issue
Block a user