github.com/klaytn/klaytn@v1.10.2/datasync/chaindatafetcher/kas/repository_contracts_test.go (about) 1 // Copyright 2020 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 kas 18 19 import ( 20 "math/big" 21 "testing" 22 23 "github.com/golang/mock/gomock" 24 "github.com/klaytn/klaytn/blockchain" 25 "github.com/klaytn/klaytn/blockchain/types" 26 "github.com/klaytn/klaytn/common" 27 "github.com/klaytn/klaytn/datasync/chaindatafetcher/kas/mocks" 28 "github.com/stretchr/testify/assert" 29 ) 30 31 func TestFilterKIPContracts_Success(t *testing.T) { 32 ctrl := gomock.NewController(t) 33 defer ctrl.Finish() 34 35 number := new(big.Int).SetInt64(1) 36 block := types.NewBlockWithHeader(&types.Header{Number: number}) 37 38 // assume that test contracts are deployed 39 var receipts types.Receipts 40 receipts = append(receipts, &types.Receipt{ContractAddress: common.HexToAddress("1"), Status: types.ReceiptStatusSuccessful}) 41 receipts = append(receipts, &types.Receipt{ContractAddress: common.HexToAddress("2"), Status: types.ReceiptStatusSuccessful}) 42 receipts = append(receipts, &types.Receipt{ContractAddress: common.HexToAddress("3"), Status: types.ReceiptStatusSuccessful}) 43 receipts = append(receipts, &types.Receipt{ContractAddress: common.HexToAddress("4"), Status: types.ReceiptStatusSuccessful}) 44 event := blockchain.ChainEvent{ 45 Block: block, 46 Receipts: receipts, 47 } 48 49 api := mocks.NewMockBlockchainAPI(ctrl) 50 51 // First contract is KIP13 only 52 setExpectation(api, &receipts[0].ContractAddress, ikip13Input, decodedTrue) 53 setExpectation(api, &receipts[0].ContractAddress, ikip13InvalidInput, decodedFalse) 54 setExpectation(api, &receipts[0].ContractAddress, ikip7Input, decodedFalse) 55 setExpectation(api, &receipts[0].ContractAddress, ikip17Input, decodedFalse) 56 57 // Second one is IKIP7 58 setExpectation(api, &receipts[1].ContractAddress, ikip13Input, decodedTrue) 59 setExpectation(api, &receipts[1].ContractAddress, ikip13InvalidInput, decodedFalse) 60 setExpectation(api, &receipts[1].ContractAddress, ikip7Input, decodedTrue) 61 setExpectation(api, &receipts[1].ContractAddress, ikip7MetadataInput, decodedTrue) 62 63 // Third one is IKIP17 64 setExpectation(api, &receipts[2].ContractAddress, ikip13Input, decodedTrue) 65 setExpectation(api, &receipts[2].ContractAddress, ikip13InvalidInput, decodedFalse) 66 setExpectation(api, &receipts[2].ContractAddress, ikip7Input, decodedFalse) 67 setExpectation(api, &receipts[2].ContractAddress, ikip17Input, decodedTrue) 68 setExpectation(api, &receipts[2].ContractAddress, ikip17MetadataInput, decodedTrue) 69 70 // Last one is not KIP 71 setExpectation(api, &receipts[3].ContractAddress, ikip13Input, decodedFalse) 72 73 fts, nfts, others, err := filterKIPContracts(api, event) 74 assert.Equal(t, 1, len(fts)) 75 assert.Equal(t, 1, len(nfts)) 76 assert.Equal(t, 2, len(others)) 77 assert.NoError(t, err) 78 }