github.com/klaytn/klaytn@v1.12.1/node/sc/vt_contract_test.go (about) 1 // Copyright 2019 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The klaytn library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package sc 18 19 import ( 20 "math/big" 21 "os" 22 "strconv" 23 "testing" 24 25 "github.com/klaytn/klaytn/accounts/abi/bind" 26 "github.com/klaytn/klaytn/common" 27 sctoken "github.com/klaytn/klaytn/contracts/sc_erc20" 28 scnft "github.com/klaytn/klaytn/contracts/sc_erc721" 29 "github.com/stretchr/testify/assert" 30 ) 31 32 // TestTokenPublicVariables checks the results of the public variables. 33 func TestTokenPublicVariables(t *testing.T) { 34 tempDir, err := os.MkdirTemp(os.TempDir(), "sc") 35 assert.NoError(t, err) 36 defer func() { 37 if err := os.RemoveAll(tempDir); err != nil { 38 t.Fatalf("fail to delete file %v", err) 39 } 40 }() 41 42 info := prepare(t, func(info *testInfo) { 43 for i := 0; i < testTxCount; i++ { 44 ops[KLAY].request(info, info.localInfo) 45 } 46 }) 47 defer info.sim.Close() 48 49 initSupply, err := info.tokenLocalBridge.INITIALSUPPLY(nil) 50 assert.NoError(t, err) 51 assert.Equal(t, "1000000000000000000000000000", initSupply.String()) 52 53 allowance, err := info.tokenLocalBridge.Allowance(nil, info.chainAuth.From, info.chainAuth.From) 54 assert.NoError(t, err) 55 assert.Equal(t, "0", allowance.String()) 56 57 balance, err := info.tokenLocalBridge.BalanceOf(nil, info.nodeAuth.From) 58 assert.NoError(t, err) 59 assert.Equal(t, "1000000000000000000000000000", balance.String()) 60 61 decimal, err := info.tokenLocalBridge.DECIMALS(nil) 62 assert.NoError(t, err) 63 assert.Equal(t, uint8(0x12), decimal) 64 65 name, err := info.tokenLocalBridge.NAME(nil) 66 assert.NoError(t, err) 67 assert.Equal(t, "ServiceChainToken", name) 68 69 symbol, err := info.tokenLocalBridge.SYMBOL(nil) 70 assert.NoError(t, err) 71 assert.Equal(t, "SCT", symbol) 72 73 _, tx, _, err := sctoken.DeployServiceChainToken(info.nodeAuth, info.sim, common.Address{0}) 74 assert.NoError(t, err) 75 info.sim.Commit() 76 assert.NotNil(t, bind.CheckWaitMined(info.sim, tx)) 77 } 78 79 // TestTokenPublicVariables checks the results of the public variables. 80 func TestNFTPublicVariables(t *testing.T) { 81 tempDir, err := os.MkdirTemp(os.TempDir(), "sc") 82 assert.NoError(t, err) 83 defer func() { 84 if err := os.RemoveAll(tempDir); err != nil { 85 t.Fatalf("fail to delete file %v", err) 86 } 87 }() 88 89 info := prepare(t, func(info *testInfo) { 90 for i := 0; i < testTxCount; i++ { 91 ops[KLAY].request(info, info.localInfo) 92 } 93 }) 94 defer info.sim.Close() 95 96 _, tx, _, err := scnft.DeployServiceChainNFT(info.nodeAuth, info.sim, common.Address{0}) 97 assert.NoError(t, err) 98 info.sim.Commit() 99 assert.NotNil(t, bind.CheckWaitMined(info.sim, tx)) 100 101 balance, err := info.nftLocalBridge.BalanceOf(nil, info.nodeAuth.From) 102 assert.Equal(t, strconv.FormatInt(testTxCount, 10), balance.String()) 103 104 bride, err := info.nftLocalBridge.Bridge(nil) 105 assert.Equal(t, info.localInfo.address, bride) 106 107 bof, err := info.nftLocalBridge.BalanceOf(nil, info.nodeAuth.From) 108 assert.Equal(t, strconv.FormatInt(testTxCount, 10), bof.String()) 109 110 approved, err := info.nftLocalBridge.GetApproved(&bind.CallOpts{From: info.nodeAuth.From}, big.NewInt(int64(testNFT))) 111 assert.Equal(t, common.Address{0}, approved) 112 113 isApproved, err := info.nftLocalBridge.IsApprovedForAll(nil, info.nodeAuth.From, info.nodeAuth.From) 114 assert.Equal(t, false, isApproved) 115 116 isOwner, err := info.nftLocalBridge.IsOwner(&bind.CallOpts{From: info.nodeAuth.From}) 117 assert.Equal(t, true, isOwner) 118 119 name, err := info.nftLocalBridge.Name(nil) 120 assert.Equal(t, "ServiceChainNFT", name) 121 122 owner, err := info.nftLocalBridge.Owner(nil) 123 assert.Equal(t, info.nodeAuth.From, owner) 124 125 ownerOf, err := info.nftLocalBridge.OwnerOf(nil, big.NewInt(int64(testNFT))) 126 assert.Equal(t, info.nodeAuth.From, ownerOf) 127 128 ifid := [4]byte{0} 129 sif, err := info.nftLocalBridge.SupportsInterface(nil, ifid) 130 assert.Equal(t, false, sif) 131 132 symbol, err := info.nftLocalBridge.Symbol(nil) 133 assert.Equal(t, "SCN", symbol) 134 135 tindex, err := info.nftLocalBridge.TokenByIndex(nil, big.NewInt(int64(0))) 136 assert.Equal(t, strconv.FormatInt(testNFT, 10), tindex.String()) 137 138 ownerByIndex, err := info.nftLocalBridge.TokenOfOwnerByIndex(nil, info.nodeAuth.From, big.NewInt(int64(0))) 139 assert.Equal(t, strconv.FormatInt(testNFT, 10), ownerByIndex.String()) 140 141 uri, err := info.nftLocalBridge.TokenURI(nil, big.NewInt(int64(0))) 142 assert.Equal(t, "", uri) 143 144 totalSupply, err := info.nftLocalBridge.TotalSupply(nil) 145 assert.Equal(t, strconv.FormatInt(testTxCount, 10), totalSupply.String()) 146 }