키 포인트
스토리 DAO는 OpenZeppelin의 자체 계약을 사용하여 소유자 만 관리 기능을 수행 할 수 있도록하여 DAPP 운영에 대한 보안 및 제어를 향상시킵니다. 스토리 DAO 계약에는 조정 가능한 수수료 및 기간 매개 변수가 있으며 승인되지 않은 변경을 방지하기 위해 보안 조치가 장착되어 소유자 만 중요한 설정을 수정할 수 있습니다.
스토리의 화이트리스트 관리는 발신자의 기여에 따라 자동 및 조건부 액세스를 허용하는 유료 기능을 통해 구현됩니다. 테스트
참고 : 견고성 테스트는 일반적으로 저수준 계약 기반 기능, 즉 스마트 계약의 내부 구조를 테스트하는 데 사용됩니다. JS 테스트는 종종 계약이 외부에서 올바르게 상호 작용할 수 있는지 테스트하는 데 사용됩니다. 이것이 최종 사용자가 할 일입니다.
- 선언이 참인지 거짓인지 확인합니다. 이 예에서는 숫자를 배치 된 계약의 초기 값과 비교합니다. "true"가 될 때마다 Assert.equals 섹션은 "True"를 나타내는 이벤트를 발행합니다.이 사건은 Truffle이 테스트 중에 듣는 것입니다.
<,>이 시점에서, 우리는 또한 프로젝트 폴더의 루트에있는 package.json 파일을 업데이트 (또는 지금까지 필요한 종속성과 향후 필요한 것)를 업데이트해야합니다. >
<🎜 🎜> <<> 참고 : 우리는 안전한 계산을위한 SAFEMATH 기능이기 때문에 서브를 빼기 위해 서브를 사용합니다.
이더 리움 dapps 및 화이트리스트 건물에 대한
블록 체인의 스마트 계약은 불변이기 때문에 배포 후 DAPP를 업데이트하는 것은 어려울 수 있습니다. 그러나 데이터 및 논리를 다른 계약으로 분리하거나 위임 된 통화를 사용하여 계약을 업그레이드하여 업그레이드 가능한 계약을 설계 할 수 있습니다. DAPP의 설계 단계에서 업그레이드 및 변경 계획은 매우 중요합니다. pragma solidity ^0.4.24;
import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract StoryDao is Ownable {
using SafeMath for uint256;
mapping(address => bool) whitelist;
uint256 public whitelistedNumber = 0;
mapping(address => bool) blacklist;
event Whitelisted(address addr, bool status);
event Blacklisted(address addr, bool status);
uint256 public daofee = 100; // 百分之几,即 100 为 1%
uint256 public whitelistfee = 10000000000000000; // 以 Wei 为单位,这是 0.01 以太币
event SubmissionCommissionChanged(uint256 newFee);
event WhitelistFeeChanged(uint256 newFee);
uint256 public durationDays = 21; // 故事章节持续时间(天)
uint256 public durationSubmissions = 1000; // 故事章节持续时间(条目)
function changedaofee(uint256 _fee) onlyOwner external {
require(_fee <= 1000); // 限制最大费用为 10%
daofee = _fee;
emit SubmissionCommissionChanged(_fee);
}
function changewhitelistfee(uint256 _fee) onlyOwner external {
require(_fee > 0); // 确保费用大于 0
whitelistfee = _fee;
emit WhitelistFeeChanged(_fee);
}
function changeDurationDays(uint256 _days) onlyOwner external {
require(_days >= 1);
durationDays = _days;
}
function changeDurationSubmissions(uint256 _subs) onlyOwner external {
require(_subs > 99);
durationSubmissions = _subs;
}
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
export default async promise => {
try {
await promise;
} catch (error) {
const invalidOpcode = error.message.search('invalid opcode') >= 0;
const outOfGas = error.message.search('out of gas') >= 0;
const revert = error.message.search('revert') >= 0;
assert(
invalidOpcode || outOfGas || revert,
'Expected throw, got \'' + error + '\' instead',
);
return;
}
assert.fail('Expected throw not received');
};
pragma solidity ^0.4.24;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/StoryDao.sol";
contract TestStoryDao {
function testDeploymentIsFine() public {
StoryDao sd = StoryDao(DeployedAddresses.StoryDao());
uint256 daofee = 100; // 百分之几,即 100 为 1%
uint256 whitelistfee = 10000000000000000; // 以 Wei 为单位,这是 0.01 以太币
uint256 durationDays = 21; // 故事章节持续时间(天)
uint256 durationSubmissions = 1000; // 故事章节持续时间(条目)
Assert.equal(sd.daofee(), daofee, "初始 DAO 费用应为 100");
Assert.equal(sd.whitelistfee(), whitelistfee, "初始白名单费用应为 0.01 以太币");
Assert.equal(sd.durationDays(), durationDays, "初始天数持续时间应设置为 3 周");
Assert.equal(sd.durationSubmissions(), durationSubmissions, "初始提交持续时间应设置为 1000 个条目");
}
}
import expectThrow from './helpers/expectThrow';
const StoryDao = artifacts.require("StoryDao");
contract('StoryDao Test', async (accounts) => {
it("should make sure environment is OK by checking that the first 3 accounts have over 20 eth", async () =>{
assert.equal(web3.eth.getBalance(accounts[0]).toNumber() > 2e+19, true, "Account 0 has more than 20 eth");
assert.equal(web3.eth.getBalance(accounts[1]).toNumber() > 2e+19, true, "Account 1 has more than 20 eth");
assert.equal(web3.eth.getBalance(accounts[2]).toNumber() > 2e+19, true, "Account 2 has more than 20 eth");
});
it("should make the deployer the owner", async () => {
let instance = await StoryDao.deployed();
assert.equal(await instance.owner(), accounts[0]);
});
it("should let owner change fee and duration", async () => {
let instance = await StoryDao.deployed();
let newDaoFee = 50;
let newWhitelistFee = 1e+10; // 1 ether
let newDayDuration = 42;
let newSubsDuration = 1500;
instance.changedaofee(newDaoFee, {from: accounts[0]});
instance.changewhitelistfee(newWhitelistFee, {from: accounts[0]});
instance.changeDurationDays(newDayDuration, {from: accounts[0]});
instance.changeDurationSubmissions(newSubsDuration, {from: accounts[0]});
assert.equal(await instance.daofee(), newDaoFee);
assert.equal(await instance.whitelistfee(), newWhitelistFee);
assert.equal(await instance.durationDays(), newDayDuration);
assert.equal(await instance.durationSubmissions(), newSubsDuration);
});
it("should forbid non-owners from changing fee and duration", async () => {
let instance = await StoryDao.deployed();
let newDaoFee = 50;
let newWhitelistFee = 1e+10; // 1 ether
let newDayDuration = 42;
let newSubsDuration = 1500;
await expectThrow(instance.changedaofee(newDaoFee, {from: accounts[1]}));
await expectThrow(instance.changewhitelistfee(newWhitelistFee, {from: accounts[1]}));
await expectThrow(instance.changeDurationDays(newDayDuration, {from: accounts[1]}));
await expectThrow(instance.changeDurationSubmissions(newSubsDuration, {from: accounts[1]}));
});
it("should make sure the owner can only change fees and duration to valid values", async () =>{
let instance = await StoryDao.deployed();
let invalidDaoFee = 20000;
let invalidDayDuration = 0;
let invalidSubsDuration = 98;
await expectThrow(instance.changedaofee(invalidDaoFee, {from: accounts[0]}));
await expectThrow(instance.changeDurationDays(invalidDayDuration, {from: accounts[0]}));
await expectThrow(instance.changeDurationSubmissions(invalidSubsDuration, {from: accounts[0]}));
})
});
pragma solidity ^0.4.24;
import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract StoryDao is Ownable {
using SafeMath for uint256;
mapping(address => bool) whitelist;
uint256 public whitelistedNumber = 0;
mapping(address => bool) blacklist;
event Whitelisted(address addr, bool status);
event Blacklisted(address addr, bool status);
uint256 public daofee = 100; // 百分之几,即 100 为 1%
uint256 public whitelistfee = 10000000000000000; // 以 Wei 为单位,这是 0.01 以太币
event SubmissionCommissionChanged(uint256 newFee);
event WhitelistFeeChanged(uint256 newFee);
uint256 public durationDays = 21; // 故事章节持续时间(天)
uint256 public durationSubmissions = 1000; // 故事章节持续时间(条目)
function changedaofee(uint256 _fee) onlyOwner external {
require(_fee <= 1000); // 限制最大费用为 10%
daofee = _fee;
emit SubmissionCommissionChanged(_fee);
}
function changewhitelistfee(uint256 _fee) onlyOwner external {
require(_fee > 0); // 确保费用大于 0
whitelistfee = _fee;
emit WhitelistFeeChanged(_fee);
}
function changeDurationDays(uint256 _days) onlyOwner external {
require(_days >= 1);
durationDays = _days;
}
function changeDurationSubmissions(uint256 _subs) onlyOwner external {
require(_subs > 99);
durationSubmissions = _subs;
}
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
DAO는 분산 된 자율 조직을 나타냅니다. 그것은 조직 구성원이 통제하고 중앙 정부의 영향을받지 않는 컴퓨터 프로그램으로 인코딩 된 규칙으로 표현되는 조직 유형입니다. DAO의 금융 거래 및 규칙은 블록 체인에 보관되어 DAPP가됩니다.
DAPP 개발은 몇 가지 과제에 직면 해 있습니다. 여기에는 이더 리움 네트워크의 확장 성 문제를 다루고, DAPP의 보안을 보장하고, 거래를위한 휘발성 가스 가격 관리 및 사용자 친화적 인 인터페이스 제공이 포함됩니다. 또한 빠르게 진화하는 블록 체인 기술 및 규정을 주시해야합니다.
위 내용은 이더 리움 DAPP 건축 : 화이트리스트 및 테스트 스토리 DAO의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!