Lottery Bet 함수 테스트 강의 중 4:36에서 'from' 관련 오류가 발생합니다.
597
작성한 질문수 1
감사하게도 강좌를 통해 스마트 컨트랙트에 대해서 배우고 있는데요,
Bet 테스트 코드 실행 시, 에러가 발생하고 있는데 어디서 문제인지 파악이 안되서 질문글 올려요
Error: The send transactions "from" field must be defined!

Lottery.sol
pragma solidity >=0.4.22 <0.9.0;
contract Lottery {
struct BetInfo {
uint256 answerBlockNumber;
address payable bettor;
byte challenges; //0xab...
}
address public owner;
uint256 private _tail;
uint256 private _head;
mapping (uint256 => BetInfo) private _bets;
uint256 private _pot;
uint256 constant internal BET_AMOUNT = 5 * 10 ** 15;
uint256 constant internal BET_BLOCK_INTERVAL = 3;
uint256 constant internal BLOCK_LIMIT = 256;
event BET(uint256 index, address bettor, uint256 amount, byte challenges, uint256 answerBlockNumber);
constructor() public {
owner = msg.sender;
}
function getPot() public view returns (uint256 pot) {
return _pot;
}
/**
* @dev 베팅을 한다. 유저는 0.005 ETH를 보내야 하고, 베팅을 1 byte 글자를 보낸다.
* 큐에 저장된 베팅 정보는 이후 distribute 함수에서 해결된다.
* @param challenges 유저가 베팅하는 글자
* @return 함수가 잘 수행되었는지 확인히는 bool 값
*/
function bet(byte challenges) public payable returns (bool result) {
// check the paater ether is sent
require(msg.value == BET_AMOUNT, "Not enoughf ETH");
// push bet to the queue
require(pushBet(challenges), "Fail to add a new Bet Info");
// emit evnet
emit BET(_tail - 1, msg.sender, msg.value, challenges, block.number + BET_BLOCK_INTERVAL);
return true;
}
// save ther bet to the queue
// 결과값 검증
// check the answer
function getBetInfo(uint256 index) public view returns (uint256 answerBlockNumber, address bettor, byte challenges) {
BetInfo memory b = _bets[index];
answerBlockNumber = b.answerBlockNumber;
bettor = b.bettor;
challenges = b.challenges;
}
// function pushBet(byte challenges) public returns (bool) {
function pushBet(byte challenges) internal returns (bool) {
BetInfo memory b;
b.bettor = msg.sender;
b.answerBlockNumber = block.number + BET_BLOCK_INTERVAL;
b.challenges = challenges;
_bets[_tail] = b;
_tail++;
return true;
}
// function popBet(uint256 index) public returns (bool) {
function popBet(uint256 index) internal returns (bool) {
delete _bets[index];
return true;
}
}
lottery.test.js
const assertRevert = require("./assertRevert");
const Lottery = artifacts.require("Lottery");
contract('Lottery', function (deployer, user1, user2) {
let lottery;
beforeEach(async () => {
lottery = await Lottery.new();
})
//it.only('getPot should return current pot', async () => {
it('getPot should return current pot', async () => {
let pot = await lottery.getPot();
assert.equal(pot, 0);
})
describe('Bet', function () {
console.log(user1);
it.only('should fail when the bet money is not 0.005 ETH', async () => {
// Fail transaction
await assertRevert(lottery.bet('0xab', { from: user1, value: 4000000000000000 }))
// transaction object {chainId, value, to, from, gas, gasPrice}
})
it('should put the bet to the bet queue with 1 bet', async () => {
// bet
await lottery.bet('0xab', { from: user1, value: 5000000000000000 })
// check contract balance == 0.005
// check bet info
// check log
})
})
});
중간에 제가 노트북을 리부트해서 서버의 정보가 날라가서 일까요??
ganache-cli -d -m tutorial로 다시 구동했는데, user1를 출력해보면 undefined가 나옵니다. ㅠㅠ
답변 3
0
아 ㅠㅠㅠ 오타가 있었습니다.
contract('Lottery', function (deployer, user1, user2) {=> []가 빠져있었네요 ㅠㅠㅠㅠㅠ!!!
contract('Lottery', function ([deployer, user1, user2]) {
truffle project 세팅관련
0
302
1
gas 계산하는 부분이 이해가 되지 않습니다.
0
324
1
폴더 안에 파일이 없습니다.
0
343
0
address payable error
0
361
1
migrations 내의 js파일에서 artifacts 객체를 불러올 수 없습니다
1
320
0
안녕하세요 강의 잘 따라와서 끝까지 잘 해냈습니다!!
0
223
0
안녕하세요 강의 정말 잘듣고있습니다.
1
489
1
안녕하세요. Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
1
252
0
setState 사용에 대해서 질문입니다.
0
303
1
bootstrap library 설치 error
0
300
0
web3.eth.sendTransaction()
0
367
0
잘 쫓아가고 있습니다만 왜 저는 빨간선이 나올까요?
0
266
0
React js 환경설정 강의 질문
0
287
1
web3오류
0
380
2
코드 원본을 받을 수 있을까요?
0
352
2
ganache-cli 명령어 질문
0
351
1
recent mode 질문
0
267
1
Gas 부족 에 대한 질문입니다.
0
301
2
geth 채굴시 unlock 이외의 방법이 있을까요?
0
294
2
테스트 코드 작성 중 오류가 발생합니다.
0
315
2
truffle migrate
0
274
1
질문입니다
0
303
2
8:22 에러
0
288
2
콘솔창에서 에러..
0
1048
5





