solmate
solmate copied to clipboard
✨ Bytes32AddressLib: `fromFirst20Bytes`
Description
Add a method for converting a right-padded bytes32 address (e.g. return value of fillLast12Bytes
) back into the original 20-byte address.
Checklist
Ensure you completed all of the steps below before submitting your pull request:
- [x] Ran
forge snapshot
? - [x] Ran
npm run lint
? - [x] Ran
forge test
?
awesome! can you add a fuzz test to ensure they're inverses over all inputs, and a plain unit test that just checks the output of fromFirst20Bytes
without running it through fillLast12Bytes
?
awesome! can you add a fuzz test to ensure they're inverses over all inputs, and a plain unit test that just checks the output of
fromFirst20Bytes
without running it throughfillLast12Bytes
?
Thanks for looking, done ser.
For the unit test, I'm reusing the same address-based values as what's in testFillLast12Bytes
so I created contract variables to reduce code duplication. I wanted to bring that up since it resulted in a change to the testFillLast12Bytes
test (now uses the new variables). If that's not ok, I'll change it back.
In the fuzz test, I have an equality assertion for the output of fillLast12Bytes
and the bytes32-casted input because I think many people will use fillLast12Bytes
and fromFirst20Bytes
in tandem (we're currently doing this).