accounts/abi: move U256Bytes to common/math (#21020)
This commit is contained in:
committed by
GitHub
parent
e872083d44
commit
ab72803e6f
@ -184,6 +184,12 @@ func U256(x *big.Int) *big.Int {
|
||||
return x.And(x, tt256m1)
|
||||
}
|
||||
|
||||
// U256Bytes converts a big Int into a 256bit EVM number.
|
||||
// This operation is destructive.
|
||||
func U256Bytes(n *big.Int) []byte {
|
||||
return PaddedBigBytes(U256(n), 32)
|
||||
}
|
||||
|
||||
// S256 interprets x as a two's complement number.
|
||||
// x must not exceed 256 bits (the result is undefined if it does) and is not modified.
|
||||
//
|
||||
|
@ -212,6 +212,16 @@ func TestU256(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestU256Bytes(t *testing.T) {
|
||||
ubytes := make([]byte, 32)
|
||||
ubytes[31] = 1
|
||||
|
||||
unsigned := U256Bytes(big.NewInt(1))
|
||||
if !bytes.Equal(unsigned, ubytes) {
|
||||
t.Errorf("expected %x got %x", ubytes, unsigned)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBigEndianByteAt(t *testing.T) {
|
||||
tests := []struct {
|
||||
x string
|
||||
|
Reference in New Issue
Block a user