//tips
//smart contract
先の流れでtransferテストも行う。こちらはAliceでのゾンビ生成後、Aliceからbobに所有ゾンビを移し、新規所有者の確認をおこなっているものである。const zombieId = result.logs[0].args.zombieId.toNumber();の部分は特殊なので忘れないようにする。
context("with the single-step transfer scenario", async () => {
it("should transfer a zombie", async () => {
const result = await contractInstance.createRandomZombie(zombieNames[0], {from: alice});
const zombieId = result.logs[0].args.zombieId.toNumber();
await contractInstance.transferFrom(alice, bob, zombieId, {from: alice});
const newOwner = await contractInstance.ownerOf(zombieId);
assert.equal(newOwner, bob);
})
次にapproveも絡めた形で確認する。
今度はAliceではなくbob側が関数を呼ぶ形となる。Aliceがゾンビを生成した後に、aliceからbobに対してトークンを動かすことの許可を与えている。その後にbobからtransferfromをかけている。openseaの販売もこれと同じ形か。
context("with the two-step transfer scenario", async () => {
it("should approve and then transfer a zombie when the approved address calls transferFrom", async () => {
const result = await contractInstance.createRandomZombie(zombieNames[0], {from: alice});
const zombieId = result.logs[0].args.zombieId.toNumber();
await contractInstance.approve(bob, zombieId, {from: alice});
await contractInstance.transferFrom(alice, bob, zombieId, {from: bob});
const newOwner = await contractInstance.ownerOf(zombieId);
assert.equal(newOwner,bob);
})