Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases for NewOverlayFromEthereumAddress #4461

Closed
wants to merge 0 commits into from

Conversation

Aviksaikat
Copy link
Contributor

@Aviksaikat Aviksaikat commented Nov 14, 2023

added 4 test cases under TestNewOverlayFromEthereumAddress to test NewOverlayFromEthereumAddress of crypto library

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

image

@Aviksaikat Aviksaikat changed the title added 4 test cases under TestNewOverlayFromEthereumAddress Added test cases for NewOverlayFromEthereumAddress Nov 14, 2023
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the nice PR. Would be great if you could rewrite it into table-test and also use standard Golang test messages ("want: ...; got/have: ...").

@Aviksaikat
Copy link
Contributor Author

Is it something like this?

func TestNewOverlayFromEthereumAddress(t *testing.T) {
   t.Parallel()

   // Define the test cases
   testCases := []struct {
       ethAddress  string
       overlayNumber int
       hash         []byte
       expected     string
   }{
       {
           ethAddress:  "1815cac638d1525b47f848daf02b7953e4edd15c",
           overlayNumber: 1,
           hash:         common.HexToHash("0x1").Bytes(),
           expected:     "a38f7a814d4b249ae9d3821e9b898019c78ac9abe248fff171782c32a3849a17",
       },
       {
           ethAddress:  "1815cac638d1525b47f848daf02b7953e4edd15c",
           overlayNumber: 1,
           hash:         common.HexToHash("0x2").Bytes(),
           expected:     "c63c10b1728dfc463c64c264f71a621fe640196979375840be42dc496b702610",
       },
       {
           ethAddress:  "d26bc1715e933bd5f8fad16310042f13abc16159",
           overlayNumber: 2,
           hash:         common.HexToHash("0x1").Bytes(),
           expected:     "9f421f9149b8e31e238cfbdc6e5e833bacf1e42f77f60874d49291292858968e",
       },
       {
           ethAddress:  "ac485e3c63dcf9b4cda9f007628bb0b6fed1c063",
           overlayNumber: 1,
           hash:         common.HexToHash("0x0").Bytes(),
           expected:     "fe3a6d582c577404fb19df64a44e00d3a3b71230a8464c0dd34af3f0791b45f2",
       },
   }

   // Run the test cases
   for _, tc := range testCases {
       ethAddressBytes, err := hex.DecodeString(tc.ethAddress)
       if err != nil {
           t.Fatal(err)
       }

       newAddress, err := crypto.NewOverlayFromEthereumAddress(ethAddressBytes, tc.overlayNumber, tc.hash)
       if err != nil {
           t.Fatal(err)
       }

       if l := len(newAddress.Bytes()); l != 32 {
           t.Errorf("got address length %v, want %v", l, 32)
       }

       if newAddress.String() != tc.expected {
           t.Errorf("want: %s; got: %s", tc.expected, newAddress.String())
       }
   }
}

@notanatol
Copy link
Contributor

can you also fix the commit message to something like chore: add test for...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants