TestRealEstate.js
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var RealEstate = artifacts.require("./RealEstate.sol");
contract('RealEstate', function(accounts){ // 컨트랙을 테스팅할 것인데 인자로 두개를 받음 Testing할 컨트랙할 이름, Accounts라는 인자를 Callback을 받음
// 현재 연결된 노드에서 쓸 수 있는 계정들. 이는 가나슈의 10개 계정을 의미]
var realEstateInstance; // real-estate 저장할 전역 변수를 저장
it("컨트랙의 소유자 초기화 테스팅", function(){ // it을 통해 어떤 테스팅을 진행할지 정의
return RealEstate.deployed().then(function(instance)
{
realEstateInstance = instance;
return realEstateInstance.owner.call(); // 주소 저장
}).then(function(owner)
{
assert.equal(owner.toUpperCase(), accounts[0].toUpperCase(), "owner가 가나슈 첫번째 계정이 동일하지 않습니다.") // 1,2가 같은지 검증하는 것 3에 들어갈 것은 같거나 다르면 출력할 것
});
});
it("가나슈 두번째 계정으로 매물 아이디 0번 매입 후 이벤트 생성 및 매입자 정보와 buyers 배열 테스팅", function() {
return RealEstate.deployed().then(function(instance) {
realEstateInstance = instance;
return realEstateInstance.buyRealEstate(0,"kk",13, {from: accounts[1], value: web3.toWei(1.5,"ether")});
}).then(function(receipt) {
assert.equal(receipt.logs.length, 1, " 이벤트 하나가 생성 되지 않았습니다.");
assert.equal(receipt.logs[0].event,"LogBuyRealEstate", "LogBuyRealEstate 이 아닙니다.");
assert.equal(receipt.logs[0].args._buyer, accounts[1], "매입자가 가나슈 두번째 계정이 아닙니다.");
assert.equal(receipt.logs[0].args._id, 0, "매물 아이디가 0이 아닙니다.");
return realEstateInstance.getBuyerInfo(0);
}).then(function(buyerInfo){
assert.equal(buyerInfo[0].toUpperCase(), accounts[1].toUpperCase(), "매입자의 계정이 가나슈 두 번째 계정과 일치하지 않습니다.");
assert.equal(web3.toAscii(buyerInfo[1]).replace(/\0/g,''),"kk"," 매입자의 이름이 kk가 아닙니다.") // 실제 값이 hex로 리턴이 된다. 따라서 저 부분을 replace로 바꿔줘야함 regex
assert.equal(buyerInfo[2], 13, "매입자의 나이가 적합하지 않습니다.");
return realEstateInstance.getAllbuyers();
}).then(function(buyers){
assert.equal(buyers[0].toUpperCase(), accounts[1].toUpperCase(), "buyers의 첫 계정이 같지 않습니다.")
})
})
});