fix unit tests for getCode method

This commit is contained in:
ramil 2021-04-21 15:11:00 +03:00
parent 36b62f9b72
commit d09b756768
3 changed files with 21 additions and 9 deletions

View File

@ -965,9 +965,10 @@ var _ = Describe("API", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal((hexutil.Bytes)(test_helpers.ContractCode))) Expect(code).To(Equal((hexutil.Bytes)(test_helpers.ContractCode)))
}) })
It("Throws an error for an account it cannot find the code for", func() { It("Returns `nil` for an account it cannot find the code for", func() {
_, err := api.GetCode(ctx, randomAddr, rpc.BlockNumberOrHashWithHash(blockHash, true)) code, err := api.GetCode(ctx, randomAddr, rpc.BlockNumberOrHashWithHash(blockHash, true))
Expect(err).To(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(code).To(BeEmpty())
}) })
}) })
}) })

View File

@ -409,13 +409,15 @@ var _ = Describe("eth state reading tests", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal((hexutil.Bytes)(test_helpers.ContractCode))) Expect(code).To(Equal((hexutil.Bytes)(test_helpers.ContractCode)))
}) })
It("Throws an error for an account it cannot find the code for", func() { It("Returns `nil` for an account it cannot find the code for", func() {
_, err := api.GetCode(ctx, randomAddr, rpc.BlockNumberOrHashWithHash(blocks[3].Hash(), true)) code, err := api.GetCode(ctx, randomAddr, rpc.BlockNumberOrHashWithHash(blocks[3].Hash(), true))
Expect(err).To(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(code).To(BeEmpty())
}) })
It("Throws an error for a contract that doesn't exist at this hieght", func() { It("Returns `nil` for a contract that doesn't exist at this height", func() {
_, err := api.GetCode(ctx, test_helpers.ContractAddr, rpc.BlockNumberOrHashWithNumber(0)) code, err := api.GetCode(ctx, test_helpers.ContractAddr, rpc.BlockNumberOrHashWithNumber(0))
Expect(err).To(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(code).To(BeEmpty())
}) })
}) })

View File

@ -204,7 +204,16 @@ var _ = Describe("Integration test", func() {
ipldCode, err := ipldClient.CodeAt(ctx, common.HexToAddress(contract.Address), nil) ipldCode, err := ipldClient.CodeAt(ctx, common.HexToAddress(contract.Address), nil)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(gethCode).To(Equal(ipldCode))
})
It("gets code of contract that doesn't exist at this height", func() {
gethCode, err := gethClient.CodeAt(ctx, common.HexToAddress(contract.Address), big.NewInt(int64(contract.BlockNumber-1)))
Expect(err).ToNot(HaveOccurred())
ipldCode, err := ipldClient.CodeAt(ctx, common.HexToAddress(contract.Address), big.NewInt(int64(contract.BlockNumber-1)))
Expect(err).ToNot(HaveOccurred())
Expect(gethCode).To(BeEmpty())
Expect(gethCode).To(Equal(ipldCode)) Expect(gethCode).To(Equal(ipldCode))
}) })
}) })