YW, but here is what you said:
"... so decided to test the ground by touching the outer part of that cable to ground. And wow lights was not flashing anymore."
So I made a direct ground from battery to frame. If I made a ground from the wires that bundle together to somewhere on ground, my light stops flickering, I'd have a junction-box as having a poor transfer to ground.
Therefore, you have to assume that your first ground test was a bad main cable off the battery; you caused a better ground from battery to ground; so it is not the j-box wires; but the battery posts that need cleaning. Use vaseline or electric grease at those battery to cable post connections, as this corrosion begins there, rather than at the j-box: having a bad ground. If I'm reading this right, see where you started and then concluded elsewhere?
Finish off cleaning the battery posts if you have not done both sides, etc. The cables are the first look see of a bad ground, starter click-click, your blinking lights, etc. So from Loose battery cable bolts to a corrosion in green or white, the due diligence is prep-clean and keep them tight.
The Prep:
That chemical reaction to the cable end is either remove the cables or bend the ends into a cup of vinegar. As if one chemical reaction to another, that corrosion is going to dissolved off of the cable. When clean, the end looks brand new, but eaten away some. That's the prep for the cable. The prep at the battery posts is to use lots of q-tips and do not let the vinny run into that battery. So work the acid off the posts one drop or swipe at a time. Let it bubble, but catch it from dropping in between the case and the lead post in other words.
The Clean:
This is where you take a single edge razor and drag the blade across the lead post to expose a fresh layer of metal, as is to drag the blade under the cable end so those two contact points are 'clean' when they touch. Finish off with dielectric grease/vaseline if in a pinch. Coat all around the bolt/washer/nut/battery post/cable end, then tighten bolts. And this is where you do not implode the post, squeeze the lead down, crack the post, or break it off, twisting the bolt too tight, i.e., get a feel for the bark-down in other words.
Tormenting the motorcycling community one post at a time